summaryrefslogtreecommitdiffstats
path: root/views/window
diff options
context:
space:
mode:
authorben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-18 00:15:37 +0000
committerben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-18 00:15:37 +0000
commit41b946d3b39411c505f66a9dba6dc052d80dde88 (patch)
tree4dcca83abfc727b02d2fc55fb97d1fc74ee9283e /views/window
parent88df2dcb0c27fcc59835d72d35960d6da6649655 (diff)
downloadchromium_src-41b946d3b39411c505f66a9dba6dc052d80dde88.zip
chromium_src-41b946d3b39411c505f66a9dba6dc052d80dde88.tar.gz
chromium_src-41b946d3b39411c505f66a9dba6dc052d80dde88.tar.bz2
Revert 85666 - Consolidate ShouldUseNativeFrame/AlwaysUseNativeFrame/UseNativeFrame spaghetti.
Now there is: ... window::ShouldUseNativeFrame() Which is basically just a pass-thru to WindowWin::ShouldUseNativeFrame() ... which can be overridden by subclasses. Native-Frame is a windows-only concept but keeping the API on Window means I don't have to update a lot of call sites. Window also gains a FrameType state member that toggles three states - default, force-native and force-custom. This supercedes the "AlwaysUseNativeFrame/AlwaysUseCustomFrame" methods on NonClientView. I have also hooked up a context menu item behind a command line flag --debug-enable-frame-toggle that allows the frame type for an individual window to be toggled, useful for debugging. BUG=none TEST=none Review URL: http://codereview.chromium.org/7036014 TBR=ben@chromium.org Review URL: http://codereview.chromium.org/6975037 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@85702 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/window')
-rw-r--r--views/window/native_window_delegate.h4
-rw-r--r--views/window/non_client_view.cc23
-rw-r--r--views/window/non_client_view.h14
-rw-r--r--views/window/window.cc20
-rw-r--r--views/window/window.h18
-rw-r--r--views/window/window_win.cc34
6 files changed, 63 insertions, 50 deletions
diff --git a/views/window/native_window_delegate.h b/views/window/native_window_delegate.h
index 12cf3cf..c88924b 100644
--- a/views/window/native_window_delegate.h
+++ b/views/window/native_window_delegate.h
@@ -35,6 +35,10 @@ class NativeWindowDelegate {
// Returns true if the window is a dialog box.
virtual bool IsDialogBox() const = 0;
+ // Returns true if the window is using a system native frame. Returns false if
+ // it is rendering its own title bar, borders and controls.
+ virtual bool IsUsingNativeFrame() const = 0;
+
// Returns the smallest size the window can be resized to by the user.
virtual gfx::Size GetMinimumSize() const = 0;
diff --git a/views/window/non_client_view.cc b/views/window/non_client_view.cc
index a930a19..5830d73 100644
--- a/views/window/non_client_view.cc
+++ b/views/window/non_client_view.cc
@@ -66,6 +66,21 @@ void NonClientView::UpdateFrame() {
frame_->UpdateFrameAfterFrameChange();
}
+bool NonClientView::UseNativeFrame() const {
+ if (frame_view_.get()) {
+ // The frame view may always require a native frame, e.g. popups on Vista+
+ // when themes are active.
+ if (frame_view_->AlwaysUseNativeFrame())
+ return true;
+
+ // The frame view may always require a custom frame, e.g. Constrained
+ // Windows.
+ if (frame_view_->AlwaysUseCustomFrame())
+ return false;
+ }
+ return frame_->ShouldUseNativeFrame();
+}
+
void NonClientView::DisableInactiveRendering(bool disable) {
frame_view_->DisableInactiveRendering(disable);
}
@@ -177,6 +192,14 @@ views::View* NonClientView::GetEventHandlerForPoint(const gfx::Point& point) {
////////////////////////////////////////////////////////////////////////////////
// NonClientFrameView, View overrides:
+bool NonClientFrameView::AlwaysUseCustomFrame() const {
+ return false;
+}
+
+bool NonClientFrameView::AlwaysUseNativeFrame() const {
+ return false;
+}
+
bool NonClientFrameView::HitTest(const gfx::Point& l) const {
// For the default case, we assume the non-client frame view never overlaps
// the client view.
diff --git a/views/window/non_client_view.h b/views/window/non_client_view.h
index 0127d8b..d678571 100644
--- a/views/window/non_client_view.h
+++ b/views/window/non_client_view.h
@@ -45,6 +45,16 @@ class NonClientFrameView : public View {
// view should be laid out within.
virtual gfx::Rect GetBoundsForClientView() const = 0;
+ // Returns true if this FrameView should always use the custom frame,
+ // regardless of the system settings. An example is the Constrained Window,
+ // which is a child window and must always provide its own frame.
+ virtual bool AlwaysUseCustomFrame() const;
+
+ // Like AlwaysUseCustomFrame, returns true if this FrameView should always use
+ // the native frame, regardless of theme settings. An example is popup/app
+ // windows, which we do not ever want to show themed.
+ virtual bool AlwaysUseNativeFrame() const;
+
virtual gfx::Rect GetWindowBoundsForClientBounds(
const gfx::Rect& client_bounds) const = 0;
@@ -151,6 +161,10 @@ class NonClientView : public View {
// |use_native_frame|.
void UpdateFrame();
+ // Returns true if the native window frame should be used, false if the
+ // NonClientView provides its own frame implementation.
+ bool UseNativeFrame() const;
+
// Prevents the window from being rendered as deactivated when |disable| is
// true, until called with |disable| false. Used when a sub-window is to be
// shown that shouldn't visually de-activate the window.
diff --git a/views/window/window.cc b/views/window/window.cc
index 8ebc366..efc9f15 100644
--- a/views/window/window.cc
+++ b/views/window/window.cc
@@ -37,8 +37,7 @@ Window::Window()
saved_maximized_state_(false),
minimum_size_(100, 100),
disable_inactive_rendering_(false),
- window_closed_(false),
- frame_type_(FRAME_TYPE_DEFAULT) {
+ window_closed_(false) {
}
Window::~Window() {
@@ -239,22 +238,9 @@ gfx::NativeWindow Window::GetNativeWindow() const {
}
bool Window::ShouldUseNativeFrame() const {
- if (frame_type_ != FRAME_TYPE_DEFAULT)
- return frame_type_ == FRAME_TYPE_FORCE_NATIVE;
return native_window_->ShouldUseNativeFrame();
}
-void Window::DebugToggleFrameType() {
- if (frame_type_ == FRAME_TYPE_DEFAULT) {
- frame_type_ = ShouldUseNativeFrame() ? FRAME_TYPE_FORCE_CUSTOM :
- FRAME_TYPE_FORCE_NATIVE;
- } else {
- frame_type_ = frame_type_ == FRAME_TYPE_FORCE_CUSTOM ?
- FRAME_TYPE_FORCE_NATIVE : FRAME_TYPE_FORCE_CUSTOM;
- }
- FrameTypeChanged();
-}
-
void Window::FrameTypeChanged() {
native_window_->FrameTypeChanged();
}
@@ -283,6 +269,10 @@ bool Window::IsDialogBox() const {
return !!window_delegate_->AsDialogDelegate();
}
+bool Window::IsUsingNativeFrame() const {
+ return non_client_view_->UseNativeFrame();
+}
+
gfx::Size Window::GetMinimumSize() const {
return non_client_view_->GetMinimumSize();
}
diff --git a/views/window/window.h b/views/window/window.h
index eb8490a..191aba4 100644
--- a/views/window/window.h
+++ b/views/window/window.h
@@ -52,12 +52,6 @@ class Window : public Widget,
Widget::InitParams widget_init_params;
};
- enum FrameType {
- FRAME_TYPE_DEFAULT, // Use whatever the default would be.
- FRAME_TYPE_FORCE_CUSTOM, // Force the custom frame.
- FRAME_TYPE_FORCE_NATIVE // Force the native frame.
- };
-
Window();
virtual ~Window();
@@ -168,16 +162,9 @@ class Window : public Widget,
// Retrieves the Window's native window handle.
gfx::NativeWindow GetNativeWindow() const;
- void set_frame_type(FrameType frame_type) { frame_type_ = frame_type; }
- FrameType frame_type() const { return frame_type_; }
-
// Whether we should be using a native frame.
bool ShouldUseNativeFrame() const;
- // Forces the frame into the alternate frame type (custom or native) depending
- // on its current state.
- void DebugToggleFrameType();
-
// Tell the window that something caused the frame type to change.
void FrameTypeChanged();
@@ -214,6 +201,7 @@ class Window : public Widget,
virtual void EnableInactiveRendering() OVERRIDE;
virtual bool IsModal() const OVERRIDE;
virtual bool IsDialogBox() const OVERRIDE;
+ virtual bool IsUsingNativeFrame() const OVERRIDE;
virtual gfx::Size GetMinimumSize() const OVERRIDE;
virtual int GetNonClientComponent(const gfx::Point& point) const OVERRIDE;
virtual bool ExecuteCommand(int command_id) OVERRIDE;
@@ -260,10 +248,6 @@ class Window : public Widget,
// Set to true if the window is in the process of closing .
bool window_closed_;
- // The current frame type in use by this window. Defaults to
- // FRAME_TYPE_DEFAULT.
- FrameType frame_type_;
-
DISALLOW_COPY_AND_ASSIGN(Window);
};
diff --git a/views/window/window_win.cc b/views/window/window_win.cc
index 8ac69b5..e73c144 100644
--- a/views/window/window_win.cc
+++ b/views/window/window_win.cc
@@ -310,7 +310,7 @@ gfx::Font WindowWin::GetWindowTitleFont() {
gfx::Insets WindowWin::GetClientAreaInsets() const {
// Returning an empty Insets object causes the default handling in
// WidgetWin::OnNCCalcSize() to be invoked.
- if (GetWindow()->ShouldUseNativeFrame())
+ if (delegate_->IsUsingNativeFrame())
return gfx::Insets();
if (IsMaximized()) {
@@ -331,7 +331,7 @@ gfx::Insets WindowWin::GetClientAreaInsets() const {
// rect when using the opaque frame.
// Note: this is only required for non-fullscreen windows. Note that
// fullscreen windows are in restored state, not maximized.
- return gfx::Insets(0, 0, 0, 0);
+ return gfx::Insets(0, 0, IsFullscreen() ? 0 : 1, 0);
}
int WindowWin::GetShowState() const {
@@ -414,7 +414,7 @@ void WindowWin::OnExitSizeMove() {
WidgetWin::OnExitSizeMove();
delegate_->OnNativeWindowEndUserBoundsChange();
- if (!GetWindow()->ShouldUseNativeFrame()) {
+ if (!ShouldUseNativeFrame()) {
// Sending SWP_FRAMECHANGED forces a non-client repaint, which fixes the
// glitch in rendering the bottom pixel of the window caused by us
// offsetting the client rect there (See comment in GetClientAreaInsets()).
@@ -438,7 +438,7 @@ void WindowWin::OnGetMinMaxInfo(MINMAXINFO* minmax_info) {
void WindowWin::OnInitMenu(HMENU menu) {
// We only need to manually enable the system menu if we're not using a native
// frame.
- if (GetWindow()->ShouldUseNativeFrame())
+ if (delegate_->IsUsingNativeFrame())
WidgetWin::OnInitMenu(menu);
bool is_fullscreen = IsFullscreen();
@@ -484,8 +484,7 @@ LRESULT WindowWin::OnMouseRange(UINT message, WPARAM w_param, LPARAM l_param) {
ExecuteSystemMenuCommand(id);
return 0;
}
- } else if (message == WM_NCLBUTTONDOWN &&
- !GetWindow()->ShouldUseNativeFrame()) {
+ } else if (message == WM_NCLBUTTONDOWN && !delegate_->IsUsingNativeFrame()) {
switch (w_param) {
case HTCLOSE:
case HTMINBUTTON:
@@ -563,7 +562,7 @@ LRESULT WindowWin::OnNCActivate(BOOL active) {
if (IsVisible())
GetWindow()->non_client_view()->SchedulePaint();
- if (!GetWindow()->ShouldUseNativeFrame()) {
+ if (!ShouldUseNativeFrame()) {
// TODO(beng, et al): Hack to redraw this window and child windows
// synchronously upon activation. Not all child windows are redrawing
// themselves leading to issues like http://crbug.com/74604
@@ -584,7 +583,6 @@ LRESULT WindowWin::OnNCActivate(BOOL active) {
}
LRESULT WindowWin::OnNCCalcSize(BOOL mode, LPARAM l_param) {
- //return 0;
// We only override the default handling if we need to specify a custom
// non-client edge width. Note that in most cases "no insets" means no
// custom width, but in fullscreen mode we want a custom width of 0.
@@ -626,7 +624,7 @@ LRESULT WindowWin::OnNCCalcSize(BOOL mode, LPARAM l_param) {
if (EdgeHasTopmostAutoHideTaskbar(ABE_LEFT, monitor))
client_rect->left += kAutoHideTaskbarThicknessPx;
if (EdgeHasTopmostAutoHideTaskbar(ABE_TOP, monitor)) {
- if (GetWindow()->ShouldUseNativeFrame()) {
+ if (delegate_->IsUsingNativeFrame()) {
// Tricky bit. Due to a bug in DwmDefWindowProc()'s handling of
// WM_NCHITTEST, having any nonclient area atop the window causes the
// caption buttons to draw onscreen but not respond to mouse
@@ -667,7 +665,7 @@ LRESULT WindowWin::OnNCCalcSize(BOOL mode, LPARAM l_param) {
LRESULT WindowWin::OnNCHitTest(const CPoint& point) {
// If the DWM is rendering the window controls, we need to give the DWM's
// default window procedure first chance to handle hit testing.
- if (GetWindow()->ShouldUseNativeFrame()) {
+ if (ShouldUseNativeFrame()) {
LRESULT result;
if (DwmDefWindowProc(GetNativeView(), WM_NCHITTEST, 0,
MAKELPARAM(point.x, point.y), &result)) {
@@ -692,14 +690,14 @@ void WindowWin::OnNCPaint(HRGN rgn) {
// When using a custom frame, we want to avoid calling DefWindowProc() since
// that may render artifacts.
SetMsgHandled((!IsActive() || is_in_size_move_) &&
- !GetWindow()->ShouldUseNativeFrame());
+ !delegate_->IsUsingNativeFrame());
}
LRESULT WindowWin::OnNCUAHDrawCaption(UINT msg, WPARAM w_param,
LPARAM l_param) {
// See comment in widget_win.h at the definition of WM_NCUAHDRAWCAPTION for
// an explanation about why we need to handle this message.
- SetMsgHandled(!GetWindow()->ShouldUseNativeFrame());
+ SetMsgHandled(!delegate_->IsUsingNativeFrame());
return 0;
}
@@ -707,7 +705,7 @@ LRESULT WindowWin::OnNCUAHDrawFrame(UINT msg, WPARAM w_param,
LPARAM l_param) {
// See comment in widget_win.h at the definition of WM_NCUAHDRAWCAPTION for
// an explanation about why we need to handle this message.
- SetMsgHandled(!GetWindow()->ShouldUseNativeFrame());
+ SetMsgHandled(!delegate_->IsUsingNativeFrame());
return 0;
}
@@ -764,7 +762,7 @@ void WindowWin::OnSysCommand(UINT notification_code, CPoint click) {
((notification_code & sc_mask) == SC_MOVE) ||
((notification_code & sc_mask) == SC_MAXIMIZE)))
return;
- if (!GetWindow()->ShouldUseNativeFrame()) {
+ if (!delegate_->IsUsingNativeFrame()) {
if ((notification_code & sc_mask) == SC_MINIMIZE ||
(notification_code & sc_mask) == SC_MAXIMIZE ||
(notification_code & sc_mask) == SC_RESTORE) {
@@ -1207,7 +1205,7 @@ void WindowWin::SetUseDragFrame(bool use_drag_frame) {
}
NonClientFrameView* WindowWin::CreateFrameViewForWindow() {
- if (GetWindow()->ShouldUseNativeFrame())
+ if (ShouldUseNativeFrame())
return new NativeFrameView(GetWindow());
return new CustomFrameView(GetWindow());
}
@@ -1234,8 +1232,8 @@ void WindowWin::FrameTypeChanged() {
// the DWM's glass non-client rendering is enabled, which is why
// DWMNCRP_ENABLED is used for the native frame case. _DISABLED means the
// DWM doesn't render glass, and so is used in the custom frame case.
- DWMNCRENDERINGPOLICY policy = GetWindow()->ShouldUseNativeFrame() ?
- DWMNCRP_ENABLED : DWMNCRP_DISABLED;
+ DWMNCRENDERINGPOLICY policy =
+ delegate_->IsUsingNativeFrame() ? DWMNCRP_ENABLED : DWMNCRP_DISABLED;
DwmSetWindowAttribute(GetNativeView(), DWMWA_NCRENDERING_POLICY,
&policy, sizeof(DWMNCRENDERINGPOLICY));
}
@@ -1309,7 +1307,7 @@ void WindowWin::UnlockUpdates() {
void WindowWin::ResetWindowRegion(bool force) {
// A native frame uses the native window region, and we don't want to mess
// with it.
- if (GetWindow()->ShouldUseNativeFrame()) {
+ if (delegate_->IsUsingNativeFrame()) {
if (force)
SetWindowRgn(NULL, TRUE);
return;