// will not allow us to resize the window larger than scree.
// Setting directly to INT_MAX somehow doesn't work, so we just devide
// by 10, which should still be large enough.
- maximum_size_.SetSize(INT_MAX / 10, INT_MAX / 10);
+ SetContentSizeConstraints(extensions::SizeConstraints(
+ gfx::Size(), gfx::Size(INT_MAX / 10, INT_MAX / 10)));
int width = 800, height = 600;
options.Get(switches::kWidth, &width);
set_background(views::Background::CreateStandardPanelBackground());
AddChildView(web_view_);
- if (has_frame() &&
- options.Get(switches::kUseContentSize, &use_content_size_) &&
- use_content_size_)
- bounds = ContentBoundsToWindowBounds(bounds);
-
#if defined(OS_WIN)
// Save initial window state.
if (fullscreen)
if (transparent() && !has_frame())
wm::SetShadowType(GetNativeWindow(), wm::SHADOW_TYPE_NONE);
+ gfx::Size size = bounds.size();
+ if (has_frame() &&
+ options.Get(switches::kUseContentSize, &use_content_size_) &&
+ use_content_size_)
+ size = ContentSizeToWindowSize(size);
+
window_->UpdateWindowIcon();
- window_->CenterWindow(bounds.size());
+ window_->CenterWindow(size);
Layout();
}
return window_->GetWindowBoundsInScreen();
}
-void NativeWindowViews::SetSizeConstraints(
- const extensions::SizeConstraints& size_constraints) {
-}
-
-extensions::SizeConstraints NativeWindowViews::GetSizeConstraints() {
- return extensions::SizeConstraints();
-}
-
-void NativeWindowViews::SetContentSizeConstraints(
- const extensions::SizeConstraints& size_constraints) {
-}
-
-extensions::SizeConstraints NativeWindowViews::GetContentSizeConstraints() {
- return extensions::SizeConstraints();
-}
-
-void NativeWindowViews::SetContentSize(const gfx::Size& size) {
- if (!has_frame()) {
- NativeWindow::SetSize(size);
- return;
- }
-
- gfx::Rect bounds = window_->GetWindowBoundsInScreen();
- bounds.set_size(size);
- SetBounds(ContentBoundsToWindowBounds(bounds));
-}
-
-gfx::Size NativeWindowViews::GetContentSize() {
- if (!has_frame())
- return GetSize();
-
- gfx::Size content_size =
- window_->non_client_view()->frame_view()->GetBoundsForClientView().size();
- if (menu_bar_ && menu_bar_visible_)
- content_size.set_height(content_size.height() - kMenuBarHeight);
- return content_size;
-}
-
-void NativeWindowViews::SetMinimumSize(const gfx::Size& size) {
- minimum_size_ = size;
-}
-
-gfx::Size NativeWindowViews::GetMinimumSize() {
- return minimum_size_;
-}
-
-void NativeWindowViews::SetMaximumSize(const gfx::Size& size) {
- maximum_size_ = size;
-}
-
-gfx::Size NativeWindowViews::GetMaximumSize() {
- return maximum_size_;
-}
-
void NativeWindowViews::SetResizable(bool resizable) {
#if defined(OS_WIN)
// WS_MAXIMIZEBOX => Maximize button
return window_bounds.size();
}
+gfx::Size NativeWindowViews::ContentSizeToWindowSize(const gfx::Size& size) {
+ if (!has_frame())
+ return size;
+
+ gfx::Size window_size(size);
+#if defined(OS_WIN)
+ gfx::Rect dpi_bounds =
+ gfx::Rect(gfx::Point(), gfx::win::DIPToScreenSize(size));
+ gfx::Rect window_bounds = gfx::win::ScreenToDIPRect(
+ window_->non_client_view()->GetWindowBoundsForClientBounds(dpi_bounds));
+ window_size = window_bounds.size();
+#endif
+
+ if (menu_bar_ && menu_bar_visible_)
+ window_size.set_height(window_size.height() + kMenuBarHeight);
+ return window_size;
+}
+
+gfx::Size NativeWindowViews::WindowSizeToContentSize(const gfx::Size& size) {
+ if (!has_frame())
+ return size;
+
+ gfx::Size content_size(size);
+#if defined(OS_WIN)
+ content_size = gfx::win::DIPToScreenSize(content_size);
+ RECT rect;
+ SetRectEmpty(&rect);
+ HWND hwnd = GetAcceleratedWidget();
+ DWORD style = ::GetWindowLong(hwnd, GWL_STYLE);
+ DWORD ex_style = ::GetWindowLong(hwnd, GWL_EXSTYLE);
+ AdjustWindowRectEx(&rect, style, FALSE, ex_style);
+ content_size.set_width(content_size.width() - (rect.right - rect.left));
+ content_size.set_height(content_size.height() - (rect.bottom - rect.top));
+ content_size = gfx::win::ScreenToDIPSize(content_size);
+#endif
+
+ if (menu_bar_ && menu_bar_visible_)
+ content_size.set_height(content_size.height() - kMenuBarHeight);
+ return content_size;
+}
+
void NativeWindowViews::HandleKeyboardEvent(
content::WebContents*,
const content::NativeWebKeyboardEvent& event) {
}
}
+gfx::Size NativeWindowViews::GetMinimumSize() {
+ return NativeWindow::GetMinimumSize();
+}
+
+gfx::Size NativeWindowViews::GetMaximumSize() {
+ return NativeWindow::GetMaximumSize();
+}
+
bool NativeWindowViews::AcceleratorPressed(const ui::Accelerator& accelerator) {
return accelerator_util::TriggerAcceleratorTableCommand(
&accelerator_table_, accelerator);
}
}
-gfx::Rect NativeWindowViews::ContentBoundsToWindowBounds(
- const gfx::Rect& bounds) {
- gfx::Point origin = bounds.origin();
-#if defined(OS_WIN)
- gfx::Rect dpi_bounds = gfx::win::DIPToScreenRect(bounds);
- gfx::Rect window_bounds = gfx::win::ScreenToDIPRect(
- window_->non_client_view()->GetWindowBoundsForClientBounds(dpi_bounds));
-#else
- gfx::Rect window_bounds =
- window_->non_client_view()->GetWindowBoundsForClientBounds(bounds);
-#endif
- // The window's position would also be changed, but we only want to change
- // the size.
- window_bounds.set_origin(origin);
-
- if (menu_bar_ && menu_bar_visible_)
- window_bounds.set_height(window_bounds.height() + kMenuBarHeight);
- return window_bounds;
-}
-
ui::WindowShowState NativeWindowViews::GetRestoredState() {
if (IsMaximized())
return ui::SHOW_STATE_MAXIMIZED;
bool IsFullscreen() const override;
void SetBounds(const gfx::Rect& bounds) override;
gfx::Rect GetBounds() override;
- void SetSizeConstraints(
- const extensions::SizeConstraints& size_constraints) override;
- extensions::SizeConstraints GetSizeConstraints() override;
- void SetContentSizeConstraints(
- const extensions::SizeConstraints& size_constraints) override;
- extensions::SizeConstraints GetContentSizeConstraints() override;
- void SetContentSize(const gfx::Size& size) override;
- gfx::Size GetContentSize() override;
- void SetMinimumSize(const gfx::Size& size) override;
- gfx::Size GetMinimumSize() override;
- void SetMaximumSize(const gfx::Size& size) override;
- gfx::Size GetMaximumSize() override;
void SetResizable(bool resizable) override;
bool IsResizable() override;
void SetAlwaysOnTop(bool top) override;
#endif
// NativeWindow:
+ gfx::Size ContentSizeToWindowSize(const gfx::Size& size) override;
+ gfx::Size WindowSizeToContentSize(const gfx::Size& size) override;
void HandleKeyboardEvent(
content::WebContents*,
const content::NativeWebKeyboardEvent& event) override;
// views::View:
+ gfx::Size GetMinimumSize() override;
+ gfx::Size GetMaximumSize() override;
bool AcceleratorPressed(const ui::Accelerator& accelerator) override;
// Register accelerators supported by the menu model.
void RegisterAccelerators(ui::MenuModel* menu_model);
- // Converts between client area and window area, since we include the menu bar
- // in client area we need to substract/add menu bar's height in convertions.
- gfx::Rect ContentBoundsToWindowBounds(const gfx::Rect& content_bounds);
-
// Returns the restore state for the window.
ui::WindowShowState GetRestoredState();
bool use_content_size_;
bool resizable_;
std::string title_;
- gfx::Size minimum_size_;
- gfx::Size maximum_size_;
gfx::Size widget_size_;
DISALLOW_COPY_AND_ASSIGN(NativeWindowViews);