Commit 5150e6e0 authored by jackhou's avatar jackhou Committed by Commit bot

[Win] Update HWND style when SizeConstraintsChanged.

Previously, caption buttons were set at creation time.
With this CL, minimize and maximize buttons can be added and
removed throughout the lifetime of a window.

BUG=412241

Review URL: https://codereview.chromium.org/581953002

Cr-Commit-Position: refs/heads/master@{#296617}
parent cc4cd11d
...@@ -938,6 +938,7 @@ void DesktopNativeWidgetAura::OnSizeConstraintsChanged() { ...@@ -938,6 +938,7 @@ void DesktopNativeWidgetAura::OnSizeConstraintsChanged() {
GetWidget()->widget_delegate()->CanMaximize()); GetWidget()->widget_delegate()->CanMaximize());
content_window_->SetProperty(aura::client::kCanResizeKey, content_window_->SetProperty(aura::client::kCanResizeKey,
GetWidget()->widget_delegate()->CanResize()); GetWidget()->widget_delegate()->CanResize());
desktop_window_tree_host_->SizeConstraintsChanged();
} }
void DesktopNativeWidgetAura::RepostNativeEvent(gfx::NativeEvent native_event) { void DesktopNativeWidgetAura::RepostNativeEvent(gfx::NativeEvent native_event) {
......
...@@ -156,6 +156,9 @@ class VIEWS_EXPORT DesktopWindowTreeHost { ...@@ -156,6 +156,9 @@ class VIEWS_EXPORT DesktopWindowTreeHost {
// Returns true if the Widget supports translucency. // Returns true if the Widget supports translucency.
virtual bool IsTranslucentWindowOpacitySupported() const = 0; virtual bool IsTranslucentWindowOpacitySupported() const = 0;
// Called when the window's size constraints change.
virtual void SizeConstraintsChanged() = 0;
}; };
} // namespace views } // namespace views
......
...@@ -454,6 +454,10 @@ bool DesktopWindowTreeHostWin::IsTranslucentWindowOpacitySupported() const { ...@@ -454,6 +454,10 @@ bool DesktopWindowTreeHostWin::IsTranslucentWindowOpacitySupported() const {
return ui::win::IsAeroGlassEnabled(); return ui::win::IsAeroGlassEnabled();
} }
void DesktopWindowTreeHostWin::SizeConstraintsChanged() {
message_handler_->SizeConstraintsChanged();
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// DesktopWindowTreeHostWin, WindowTreeHost implementation: // DesktopWindowTreeHostWin, WindowTreeHost implementation:
......
...@@ -104,6 +104,7 @@ class VIEWS_EXPORT DesktopWindowTreeHostWin ...@@ -104,6 +104,7 @@ class VIEWS_EXPORT DesktopWindowTreeHostWin
virtual void OnNativeWidgetBlur() OVERRIDE; virtual void OnNativeWidgetBlur() OVERRIDE;
virtual bool IsAnimatingClosed() const OVERRIDE; virtual bool IsAnimatingClosed() const OVERRIDE;
virtual bool IsTranslucentWindowOpacitySupported() const OVERRIDE; virtual bool IsTranslucentWindowOpacitySupported() const OVERRIDE;
virtual void SizeConstraintsChanged() OVERRIDE;
// Overridden from aura::WindowTreeHost: // Overridden from aura::WindowTreeHost:
virtual ui::EventSource* GetEventSource() OVERRIDE; virtual ui::EventSource* GetEventSource() OVERRIDE;
......
...@@ -850,6 +850,10 @@ bool DesktopWindowTreeHostX11::IsTranslucentWindowOpacitySupported() const { ...@@ -850,6 +850,10 @@ bool DesktopWindowTreeHostX11::IsTranslucentWindowOpacitySupported() const {
return false; return false;
} }
void DesktopWindowTreeHostX11::SizeConstraintsChanged() {
UpdateMinAndMaxSize();
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// DesktopWindowTreeHostX11, aura::WindowTreeHost implementation: // DesktopWindowTreeHostX11, aura::WindowTreeHost implementation:
......
...@@ -146,6 +146,7 @@ class VIEWS_EXPORT DesktopWindowTreeHostX11 ...@@ -146,6 +146,7 @@ class VIEWS_EXPORT DesktopWindowTreeHostX11
virtual void OnNativeWidgetBlur() OVERRIDE; virtual void OnNativeWidgetBlur() OVERRIDE;
virtual bool IsAnimatingClosed() const OVERRIDE; virtual bool IsAnimatingClosed() const OVERRIDE;
virtual bool IsTranslucentWindowOpacitySupported() const OVERRIDE; virtual bool IsTranslucentWindowOpacitySupported() const OVERRIDE;
virtual void SizeConstraintsChanged() OVERRIDE;
// Overridden from aura::WindowTreeHost: // Overridden from aura::WindowTreeHost:
virtual ui::EventSource* GetEventSource() OVERRIDE; virtual ui::EventSource* GetEventSource() OVERRIDE;
......
...@@ -81,14 +81,19 @@ void CalculateWindowStylesFromInitParams( ...@@ -81,14 +81,19 @@ void CalculateWindowStylesFromInitParams(
} }
// Else, no break. Fall through to TYPE_WINDOW. // Else, no break. Fall through to TYPE_WINDOW.
case Widget::InitParams::TYPE_WINDOW: { case Widget::InitParams::TYPE_WINDOW: {
*style |= WS_SYSMENU | WS_CAPTION; // WS_OVERLAPPEDWINDOW is equivalent to:
bool can_resize = widget_delegate->CanResize(); // WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU |
bool can_maximize = widget_delegate->CanMaximize(); // WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX
if (can_maximize) { *style |= WS_OVERLAPPEDWINDOW;
*style |= WS_OVERLAPPEDWINDOW; if (!widget_delegate->CanMaximize())
} else if (can_resize || params.remove_standard_frame) { *style &= ~WS_MAXIMIZEBOX;
*style |= WS_OVERLAPPED | WS_THICKFRAME; if (!widget_delegate->CanMinimize())
} *style &= ~WS_MINIMIZEBOX;
if (!widget_delegate->CanResize())
*style &= ~(WS_THICKFRAME | WS_MAXIMIZEBOX);
if (params.remove_standard_frame)
*style &= ~(WS_MINIMIZEBOX | WS_MAXIMIZEBOX);
if (native_widget_delegate->IsDialogBox()) { if (native_widget_delegate->IsDialogBox()) {
*style |= DS_MODALFRAME; *style |= DS_MODALFRAME;
// NOTE: Turning this off means we lose the close button, which is bad. // NOTE: Turning this off means we lose the close button, which is bad.
......
...@@ -868,6 +868,23 @@ void HWNDMessageHandler::SetFullscreen(bool fullscreen) { ...@@ -868,6 +868,23 @@ void HWNDMessageHandler::SetFullscreen(bool fullscreen) {
PerformDwmTransition(); PerformDwmTransition();
} }
void HWNDMessageHandler::SizeConstraintsChanged() {
LONG style = GetWindowLong(hwnd(), GWL_STYLE);
if (delegate_->CanResize()) {
style |= WS_THICKFRAME | WS_MAXIMIZEBOX;
if (!delegate_->CanMaximize())
style &= ~WS_MAXIMIZEBOX;
} else {
style &= ~(WS_THICKFRAME | WS_MAXIMIZEBOX);
}
if (delegate_->CanMinimize()) {
style |= WS_MINIMIZEBOX;
} else {
style &= ~WS_MINIMIZEBOX;
}
SetWindowLong(hwnd(), GWL_STYLE, style);
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// HWNDMessageHandler, InputMethodDelegate implementation: // HWNDMessageHandler, InputMethodDelegate implementation:
......
...@@ -205,6 +205,9 @@ class VIEWS_EXPORT HWNDMessageHandler : ...@@ -205,6 +205,9 @@ class VIEWS_EXPORT HWNDMessageHandler :
void SetFullscreen(bool fullscreen); void SetFullscreen(bool fullscreen);
// Updates the window style to reflect whether it can be resized or maximized.
void SizeConstraintsChanged();
private: private:
typedef std::set<DWORD> TouchIDs; typedef std::set<DWORD> TouchIDs;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment