diff options
author | wtc@chromium.org <wtc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-27 00:15:06 +0000 |
---|---|---|
committer | wtc@chromium.org <wtc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-27 00:15:06 +0000 |
commit | 96d2a75e2afc65b2bed77c6808200ef89d103c52 (patch) | |
tree | 8ce04aa79e7d954fb8499a8829c9251828e652f7 /views | |
parent | 03c52686ea954648d3e9091ca78ceb9fcc8b6dad (diff) | |
download | chromium_src-96d2a75e2afc65b2bed77c6808200ef89d103c52.zip chromium_src-96d2a75e2afc65b2bed77c6808200ef89d103c52.tar.gz chromium_src-96d2a75e2afc65b2bed77c6808200ef89d103c52.tar.bz2 |
Revert 86914 - Move a bunch of functions from Window onto Widget.
Many tests in browser_tests crashed with a LOG(DFATAL) message on Chrome OS:
[28862:28862:0526/153905:3290241082989:FATAL:browser_main.cc(955)] GLib-GObject: invalid (NULL) pointer instance
Backtrace:
base::debug::StackTrace::StackTrace() [0x33308d6]
logging::LogMessage::~LogMessage() [0x334df2e]
(anonymous namespace)::GLibLogHandler() [0x7c7d45]
0x2ab2a37a7fb9
0x2ab2a37a83d3
0x2ab2a313302a
0x2ab2a31315c5
views::NativeWidgetGtk::InitNativeWidget() [0x1a30dcf]
views::Widget::Init() [0x1a37fa7]
NativeTabContentsViewGtk::InitNativeTabContentsView() [0x10c6b83]
TabContentsViewViews::CreateView() [0x397ac46]
TabContents::TabContents() [0x1501e09]
Browser::TabContentsFactory() [0xc84725]
browser::Navigate() [0xc954c7]
Browser::AddSelectedTabWithURL() [0xc76d9e]
(anonymous namespace)::InitializeBrowser() [0x70be3d]
InProcessBrowserTest::CreateBrowser() [0x70d178]
InProcessBrowserTest::RunTestOnMainThreadLoop() [0x70d34a]
[...snipped...]
BUG=72040
TEST=none
Review URL: http://codereview.chromium.org/7075019
R=msw@chromium.org
TBR=ben@chromium.org
Review URL: http://codereview.chromium.org/6976040
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@86939 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views')
-rw-r--r-- | views/widget/native_widget.h | 11 | ||||
-rw-r--r-- | views/widget/native_widget_gtk.cc | 64 | ||||
-rw-r--r-- | views/widget/native_widget_gtk.h | 17 | ||||
-rw-r--r-- | views/widget/native_widget_views.cc | 40 | ||||
-rw-r--r-- | views/widget/native_widget_views.h | 11 | ||||
-rw-r--r-- | views/widget/native_widget_win.cc | 55 | ||||
-rw-r--r-- | views/widget/native_widget_win.h | 14 | ||||
-rw-r--r-- | views/widget/widget.cc | 36 | ||||
-rw-r--r-- | views/widget/widget.h | 42 | ||||
-rw-r--r-- | views/window/native_window.h | 12 | ||||
-rw-r--r-- | views/window/native_window_gtk.cc | 88 | ||||
-rw-r--r-- | views/window/native_window_gtk.h | 25 | ||||
-rw-r--r-- | views/window/native_window_views.cc | 49 | ||||
-rw-r--r-- | views/window/native_window_views.h | 12 | ||||
-rw-r--r-- | views/window/native_window_win.cc | 70 | ||||
-rw-r--r-- | views/window/native_window_win.h | 18 | ||||
-rw-r--r-- | views/window/window.cc | 101 | ||||
-rw-r--r-- | views/window/window.h | 54 |
18 files changed, 409 insertions, 310 deletions
diff --git a/views/widget/native_widget.h b/views/widget/native_widget.h index 0801971..2f12fbd 100644 --- a/views/widget/native_widget.h +++ b/views/widget/native_widget.h @@ -142,17 +142,10 @@ class NativeWidget { virtual void CloseNow() = 0; virtual void Show() = 0; virtual void Hide() = 0; + virtual void SetOpacity(unsigned char opacity) = 0; + virtual void SetAlwaysOnTop(bool on_top) = 0; virtual bool IsVisible() const = 0; - virtual void Activate() = 0; - virtual void Deactivate() = 0; virtual bool IsActive() const = 0; - virtual void SetAlwaysOnTop(bool always_on_top) = 0; - virtual void Maximize() = 0; - virtual void Minimize() = 0; - virtual bool IsMaximized() const = 0; - virtual bool IsMinimized() const = 0; - virtual void Restore() = 0; - virtual void SetOpacity(unsigned char opacity) = 0; virtual bool IsAccessibleWidget() const = 0; virtual bool ContainsNativeView(gfx::NativeView native_view) const = 0; virtual void RunShellDrag(View* view, diff --git a/views/widget/native_widget_gtk.cc b/views/widget/native_widget_gtk.cc index dfcd4d5..410e4de 100644 --- a/views/widget/native_widget_gtk.cc +++ b/views/widget/native_widget_gtk.cc @@ -284,7 +284,6 @@ bool NativeWidgetGtk::debug_paint_enabled_ = false; NativeWidgetGtk::NativeWidgetGtk(internal::NativeWidgetDelegate* delegate) : is_window_(false), - window_state_(GDK_WINDOW_STATE_WITHDRAWN), delegate_(delegate), widget_(NULL), window_contents_(NULL), @@ -717,8 +716,6 @@ void NativeWidgetGtk::InitNativeWidget(const Widget::InitParams& params) { G_CALLBACK(&OnDragEndThunk), this); g_signal_connect(window_contents_, "drag_failed", G_CALLBACK(&OnDragFailedThunk), this); - g_signal_connect(G_OBJECT(GetNativeWindow()), "window-state-event", - G_CALLBACK(&OnWindowStateEventThunk), this); tooltip_manager_.reset(new TooltipManagerGtk(this)); @@ -960,21 +957,13 @@ void NativeWidgetGtk::Hide() { } } -bool NativeWidgetGtk::IsVisible() const { - return GTK_WIDGET_VISIBLE(GetNativeView()); -} - -void NativeWidgetGtk::Activate() { - gtk_window_present(GetNativeWindow()); -} - -void NativeWidgetGtk::Deactivate() { - gdk_window_lower(GTK_WIDGET(GetNativeView())->window); -} - -bool NativeWidgetGtk::IsActive() const { - DCHECK(!child_); - return is_active_; +void NativeWidgetGtk::SetOpacity(unsigned char opacity) { + opacity_ = opacity; + if (widget_) { + // We can only set the opacity when the widget has been realized. + gdk_window_set_opacity(widget_->window, static_cast<gdouble>(opacity) / + static_cast<gdouble>(255)); + } } void NativeWidgetGtk::SetAlwaysOnTop(bool on_top) { @@ -984,36 +973,13 @@ void NativeWidgetGtk::SetAlwaysOnTop(bool on_top) { gtk_window_set_keep_above(GTK_WINDOW(widget_), on_top); } -void NativeWidgetGtk::Maximize() { - gtk_window_maximize(GetNativeWindow()); -} - -void NativeWidgetGtk::Minimize() { - gtk_window_iconify(GetNativeWindow()); -} - -bool NativeWidgetGtk::IsMaximized() const { - return window_state_ & GDK_WINDOW_STATE_MAXIMIZED; -} - -bool NativeWidgetGtk::IsMinimized() const { - return window_state_ & GDK_WINDOW_STATE_ICONIFIED; -} - -void NativeWidgetGtk::Restore() { - if (IsMaximized()) - gtk_window_unmaximize(GetNativeWindow()); - else if (IsMinimized()) - gtk_window_deiconify(GetNativeWindow()); +bool NativeWidgetGtk::IsVisible() const { + return GTK_WIDGET_VISIBLE(widget_); } -void NativeWidgetGtk::SetOpacity(unsigned char opacity) { - opacity_ = opacity; - if (widget_) { - // We can only set the opacity when the widget has been realized. - gdk_window_set_opacity(widget_->window, static_cast<gdouble>(opacity) / - static_cast<gdouble>(255)); - } +bool NativeWidgetGtk::IsActive() const { + DCHECK(!child_); + return is_active_; } bool NativeWidgetGtk::IsAccessibleWidget() const { @@ -1395,12 +1361,6 @@ void NativeWidgetGtk::OnMap(GtkWidget* widget) { void NativeWidgetGtk::OnHide(GtkWidget* widget) { } -gboolean NativeWidgetGtk::OnWindowStateEvent(GtkWidget* widget, - GdkEventWindowState* event) { - window_state_ = event->new_window_state; - return FALSE; -} - void NativeWidgetGtk::HandleXGrabBroke() { } diff --git a/views/widget/native_widget_gtk.h b/views/widget/native_widget_gtk.h index ffc0209..d29fee3 100644 --- a/views/widget/native_widget_gtk.h +++ b/views/widget/native_widget_gtk.h @@ -178,17 +178,10 @@ class NativeWidgetGtk : public NativeWidget, virtual void CloseNow() OVERRIDE; virtual void Show() OVERRIDE; virtual void Hide() OVERRIDE; + virtual void SetOpacity(unsigned char opacity) OVERRIDE; + virtual void SetAlwaysOnTop(bool on_top) OVERRIDE; virtual bool IsVisible() const OVERRIDE; - virtual void Activate() OVERRIDE; - virtual void Deactivate() OVERRIDE; virtual bool IsActive() const OVERRIDE; - virtual void SetAlwaysOnTop(bool always_on_top) OVERRIDE; - virtual void Maximize() OVERRIDE; - virtual void Minimize() OVERRIDE; - virtual bool IsMaximized() const OVERRIDE; - virtual bool IsMinimized() const OVERRIDE; - virtual void Restore() OVERRIDE; - virtual void SetOpacity(unsigned char opacity) OVERRIDE; virtual bool IsAccessibleWidget() const OVERRIDE; virtual bool ContainsNativeView(gfx::NativeView native_view) const OVERRIDE; virtual void RunShellDrag(View* view, @@ -252,8 +245,6 @@ class NativeWidgetGtk : public NativeWidget, CHROMEGTK_CALLBACK_0(NativeWidgetGtk, void, OnShow); CHROMEGTK_CALLBACK_0(NativeWidgetGtk, void, OnMap); CHROMEGTK_CALLBACK_0(NativeWidgetGtk, void, OnHide); - CHROMEGTK_CALLBACK_1(NativeWidgetGtk, gboolean, OnWindowStateEvent, - GdkEventWindowState*); // Invoked when gtk grab is stolen by other GtkWidget in the same // application. @@ -266,10 +257,6 @@ class NativeWidgetGtk : public NativeWidget, // Are we a subclass of NativeWindowGtk? bool is_window_; - // State of the window, such as fullscreen, hidden... - // TODO(beng): move to private once NativeWindowGtk no longer refers to it. - GdkWindowState window_state_; - private: class DropObserver; friend class DropObserver; diff --git a/views/widget/native_widget_views.cc b/views/widget/native_widget_views.cc index e4dd08d..d1bc2d5 100644 --- a/views/widget/native_widget_views.cc +++ b/views/widget/native_widget_views.cc @@ -177,50 +177,20 @@ void NativeWidgetViews::Hide() { view_->SetVisible(false); } -bool NativeWidgetViews::IsVisible() const { - return view_->IsVisible(); -} - -void NativeWidgetViews::Activate() { - NOTIMPLEMENTED(); -} - -void NativeWidgetViews::Deactivate() { +void NativeWidgetViews::SetOpacity(unsigned char opacity) { NOTIMPLEMENTED(); } -bool NativeWidgetViews::IsActive() const { - return active_; -} - void NativeWidgetViews::SetAlwaysOnTop(bool on_top) { NOTIMPLEMENTED(); } -void NativeWidgetViews::Maximize() { - NOTIMPLEMENTED(); -} - -void NativeWidgetViews::Minimize() { - NOTIMPLEMENTED(); -} - -bool NativeWidgetViews::IsMaximized() const { - NOTIMPLEMENTED(); - return false; -} - -bool NativeWidgetViews::IsMinimized() const { - NOTIMPLEMENTED(); - return false; -} - -void NativeWidgetViews::Restore() { - NOTIMPLEMENTED(); +bool NativeWidgetViews::IsVisible() const { + return view_->IsVisible(); } -void NativeWidgetViews::SetOpacity(unsigned char opacity) { - NOTIMPLEMENTED(); +bool NativeWidgetViews::IsActive() const { + return active_; } bool NativeWidgetViews::IsAccessibleWidget() const { diff --git a/views/widget/native_widget_views.h b/views/widget/native_widget_views.h index be6fbc6..63a5908 100644 --- a/views/widget/native_widget_views.h +++ b/views/widget/native_widget_views.h @@ -66,17 +66,10 @@ class NativeWidgetViews : public NativeWidget { virtual void CloseNow() OVERRIDE; virtual void Show() OVERRIDE; virtual void Hide() OVERRIDE; + virtual void SetOpacity(unsigned char opacity) OVERRIDE; + virtual void SetAlwaysOnTop(bool on_top) OVERRIDE; virtual bool IsVisible() const OVERRIDE; - virtual void Activate() OVERRIDE; - virtual void Deactivate() OVERRIDE; virtual bool IsActive() const OVERRIDE; - virtual void SetAlwaysOnTop(bool always_on_top) OVERRIDE; - virtual void Maximize() OVERRIDE; - virtual void Minimize() OVERRIDE; - virtual bool IsMaximized() const OVERRIDE; - virtual bool IsMinimized() const OVERRIDE; - virtual void Restore() OVERRIDE; - virtual void SetOpacity(unsigned char opacity) OVERRIDE; virtual bool IsAccessibleWidget() const OVERRIDE; virtual bool ContainsNativeView(gfx::NativeView native_view) const OVERRIDE; virtual void RunShellDrag(View* view, diff --git a/views/widget/native_widget_win.cc b/views/widget/native_widget_win.cc index 36a5d23..3ea4942 100644 --- a/views/widget/native_widget_win.cc +++ b/views/widget/native_widget_win.cc @@ -394,57 +394,25 @@ void NativeWidgetWin::Hide() { } } -bool NativeWidgetWin::IsVisible() const { - return !!::IsWindowVisible(hwnd()); +void NativeWidgetWin::SetOpacity(unsigned char opacity) { + layered_alpha_ = static_cast<BYTE>(opacity); } -void NativeWidgetWin::Activate() { - if (IsMinimized()) - ::ShowWindow(GetNativeView(), SW_RESTORE); - ::SetWindowPos(GetNativeView(), HWND_TOP, 0, 0, 0, 0, - SWP_NOSIZE | SWP_NOMOVE); - SetForegroundWindow(GetNativeView()); +void NativeWidgetWin::SetAlwaysOnTop(bool on_top) { + if (on_top) + set_window_ex_style(window_ex_style() | WS_EX_TOPMOST); + else + set_window_ex_style(window_ex_style() & ~WS_EX_TOPMOST); } -void NativeWidgetWin::Deactivate() { - HWND hwnd = ::GetNextWindow(GetNativeView(), GW_HWNDNEXT); - if (hwnd) - ::SetForegroundWindow(hwnd); +bool NativeWidgetWin::IsVisible() const { + return !!::IsWindowVisible(hwnd()); } bool NativeWidgetWin::IsActive() const { return IsWindowActive(hwnd()); } -void NativeWidgetWin::SetAlwaysOnTop(bool on_top) { - ::SetWindowPos(GetNativeView(), on_top ? HWND_TOPMOST : HWND_NOTOPMOST, - 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); -} - -void NativeWidgetWin::Maximize() { - ExecuteSystemMenuCommand(SC_MAXIMIZE); -} - -void NativeWidgetWin::Minimize() { - ExecuteSystemMenuCommand(SC_MINIMIZE); -} - -bool NativeWidgetWin::IsMaximized() const { - return !!::IsZoomed(GetNativeView()); -} - -bool NativeWidgetWin::IsMinimized() const { - return !!::IsIconic(GetNativeView()); -} - -void NativeWidgetWin::Restore() { - ExecuteSystemMenuCommand(SC_RESTORE); -} - -void NativeWidgetWin::SetOpacity(unsigned char opacity) { - layered_alpha_ = static_cast<BYTE>(opacity); -} - bool NativeWidgetWin::IsAccessibleWidget() const { return screen_reader_active_; } @@ -1029,11 +997,6 @@ void NativeWidgetWin::SetInitialFocus() { v->RequestFocus(); } -void NativeWidgetWin::ExecuteSystemMenuCommand(int command) { - if (command) - SendMessage(GetNativeView(), WM_SYSCOMMAND, command, 0); -} - //////////////////////////////////////////////////////////////////////////////// // NativeWidgetWin, private: diff --git a/views/widget/native_widget_win.h b/views/widget/native_widget_win.h index f576d96..8fc0589 100644 --- a/views/widget/native_widget_win.h +++ b/views/widget/native_widget_win.h @@ -197,17 +197,10 @@ class NativeWidgetWin : public ui::WindowImpl, virtual void CloseNow() OVERRIDE; virtual void Show() OVERRIDE; virtual void Hide() OVERRIDE; + virtual void SetOpacity(unsigned char opacity) OVERRIDE; + virtual void SetAlwaysOnTop(bool on_top) OVERRIDE; virtual bool IsVisible() const OVERRIDE; - virtual void Activate() OVERRIDE; - virtual void Deactivate() OVERRIDE; virtual bool IsActive() const OVERRIDE; - virtual void SetAlwaysOnTop(bool always_on_top) OVERRIDE; - virtual void Maximize() OVERRIDE; - virtual void Minimize() OVERRIDE; - virtual bool IsMaximized() const OVERRIDE; - virtual bool IsMinimized() const OVERRIDE; - virtual void Restore() OVERRIDE; - virtual void SetOpacity(unsigned char opacity) OVERRIDE; virtual bool IsAccessibleWidget() const OVERRIDE; virtual bool ContainsNativeView(gfx::NativeView native_view) const OVERRIDE; virtual void RunShellDrag(View* view, @@ -394,9 +387,6 @@ class NativeWidgetWin : public ui::WindowImpl, // button if there is one, otherwise the to the Cancel button. virtual void SetInitialFocus(); - // Executes the specified SC_command. - void ExecuteSystemMenuCommand(int command); - // The TooltipManager. // WARNING: RootView's destructor calls into the TooltipManager. As such, this // must be destroyed AFTER root_view_. diff --git a/views/widget/widget.cc b/views/widget/widget.cc index 4f15d68..8b4e793 100644 --- a/views/widget/widget.cc +++ b/views/widget/widget.cc @@ -213,46 +213,18 @@ void Widget::Hide() { native_widget_->Hide(); } -void Widget::Activate() { - native_widget_->Activate(); -} - -void Widget::Deactivate() { - native_widget_->Deactivate(); -} - bool Widget::IsActive() const { return native_widget_->IsActive(); } -void Widget::SetAlwaysOnTop(bool on_top) { - native_widget_->SetAlwaysOnTop(on_top); -} - -void Widget::Maximize() { - native_widget_->Maximize(); -} - -void Widget::Minimize() { - native_widget_->Minimize(); -} - -void Widget::Restore() { - native_widget_->Restore(); -} - -bool Widget::IsMaximized() const { - return native_widget_->IsMaximized(); -} - -bool Widget::IsMinimized() const { - return native_widget_->IsMinimized(); -} - void Widget::SetOpacity(unsigned char opacity) { native_widget_->SetOpacity(opacity); } +void Widget::SetAlwaysOnTop(bool on_top) { + native_widget_->SetAlwaysOnTop(on_top); +} + View* Widget::GetRootView() { if (!root_view_.get()) { // First time the root view is being asked for, create it now. diff --git a/views/widget/widget.h b/views/widget/widget.h index aad6331..c6f8158 100644 --- a/views/widget/widget.h +++ b/views/widget/widget.h @@ -16,16 +16,6 @@ #include "views/focus/focus_manager.h" #include "views/widget/native_widget_delegate.h" -#if defined(OS_WIN) -// Windows headers define macros for these function names which screw with us. -#if defined(IsMaximized) -#undef IsMaximized -#endif -#if defined(IsMinimized) -#undef IsMinimized -#endif -#endif - namespace gfx { class Canvas; class Path; @@ -230,37 +220,18 @@ class Widget : public internal::NativeWidgetDelegate, void CloseNow(); // Shows or hides the widget, without changing activation state. - virtual void Show(); + void Show(); void Hide(); - // Activates the widget, assuming it already exists and is visible. - void Activate(); - - // Deactivates the widget, making the next window in the Z order the active - // window. - void Deactivate(); - - // Returns whether the Widget is the currently active window. - virtual bool IsActive() const; - - // Sets the widget to be on top of all other widgets in the windowing system. - void SetAlwaysOnTop(bool on_top); - - // Maximizes/minimizes/restores the window. - void Maximize(); - void Minimize(); - void Restore(); - - // Whether or not the window is maximized or minimized. - virtual bool IsMaximized() const; - bool IsMinimized() const; - // Sets the opacity of the widget. This may allow widgets behind the widget // in the Z-order to become visible, depending on the capabilities of the // underlying windowing system. Note that the caller must then schedule a // repaint to allow this change to take effect. void SetOpacity(unsigned char opacity); + // Sets the widget to be on top of all other widgets in the windowing system. + void SetAlwaysOnTop(bool on_top); + // Returns the View at the root of the View hierarchy contained by this // Widget. View* GetRootView(); @@ -276,7 +247,10 @@ class Widget : public internal::NativeWidgetDelegate, bool is_secondary_widget() const { return is_secondary_widget_; } // Returns whether the Widget is visible to the user. - virtual bool IsVisible() const; + bool IsVisible() const; + + // Returns whether the Widget is the currently active window. + bool IsActive() const; // Returns whether the Widget is customized for accessibility. bool IsAccessibleWidget() const; diff --git a/views/window/native_window.h b/views/window/native_window.h index 0ede59b..0e83f30 100644 --- a/views/window/native_window.h +++ b/views/window/native_window.h @@ -91,11 +91,23 @@ class NativeWindow { virtual void SetWindowBounds(const gfx::Rect& bounds, gfx::NativeWindow other_window) = 0; + virtual void HideWindow() = 0; + virtual void Activate() = 0; + virtual void Deactivate() = 0; + virtual void Maximize() = 0; + virtual void Minimize() = 0; + virtual void Restore() = 0; + virtual bool IsActive() const = 0; + virtual bool IsVisible() const = 0; + virtual bool IsMaximized() const = 0; + virtual bool IsMinimized() const = 0; virtual void SetFullscreen(bool fullscreen) = 0; virtual bool IsFullscreen() const = 0; + virtual void SetAlwaysOnTop(bool always_on_top) = 0; virtual void SetUseDragFrame(bool use_drag_frame) = 0; virtual NonClientFrameView* CreateFrameViewForWindow() = 0; virtual void UpdateFrameAfterFrameChange() = 0; + virtual gfx::NativeWindow GetNativeWindow() const = 0; virtual bool ShouldUseNativeFrame() const = 0; virtual void FrameTypeChanged() = 0; }; diff --git a/views/window/native_window_gtk.cc b/views/window/native_window_gtk.cc index d65d9c0..4e25fb4 100644 --- a/views/window/native_window_gtk.cc +++ b/views/window/native_window_gtk.cc @@ -80,6 +80,7 @@ namespace views { NativeWindowGtk::NativeWindowGtk(internal::NativeWindowDelegate* delegate) : NativeWidgetGtk(delegate->AsNativeWidgetDelegate()), delegate_(delegate), + window_state_(GDK_WINDOW_STATE_WITHDRAWN), window_closed_(false) { is_window_ = true; } @@ -181,6 +182,14 @@ void NativeWindowGtk::OnSizeAllocate(GtkWidget* widget, SaveWindowPosition(); } +gboolean NativeWindowGtk::OnWindowStateEvent(GtkWidget* widget, + GdkEventWindowState* event) { + window_state_ = event->new_window_state; + if (!(window_state_ & GDK_WINDOW_STATE_WITHDRAWN)) + SaveWindowPosition(); + return FALSE; +} + gboolean NativeWindowGtk::OnLeaveNotify(GtkWidget* widget, GdkEventCrossing* event) { gdk_window_set_cursor(widget->window, gfx::GetCursor(GDK_LEFT_PTR)); @@ -198,6 +207,8 @@ void NativeWindowGtk::InitNativeWidget(const Widget::InitParams& params) { g_signal_connect(G_OBJECT(GetNativeWindow()), "configure-event", G_CALLBACK(CallConfigureEvent), this); + g_signal_connect(G_OBJECT(GetNativeWindow()), "window-state-event", + G_CALLBACK(CallWindowStateEvent), this); } //////////////////////////////////////////////////////////////////////////////// @@ -291,6 +302,51 @@ void NativeWindowGtk::SetWindowBounds(const gfx::Rect& bounds, NativeWidgetGtk::SetBounds(bounds); } +void NativeWindowGtk::HideWindow() { + GetWindow()->Hide(); +} + +void NativeWindowGtk::Activate() { + gtk_window_present(GTK_WINDOW(GetNativeView())); +} + +void NativeWindowGtk::Deactivate() { + gdk_window_lower(GTK_WIDGET(GetNativeView())->window); +} + +void NativeWindowGtk::Maximize() { + gtk_window_maximize(GetNativeWindow()); +} + +void NativeWindowGtk::Minimize() { + gtk_window_iconify(GetNativeWindow()); +} + +void NativeWindowGtk::Restore() { + if (IsMaximized()) + gtk_window_unmaximize(GetNativeWindow()); + else if (IsMinimized()) + gtk_window_deiconify(GetNativeWindow()); + else if (IsFullscreen()) + SetFullscreen(false); +} + +bool NativeWindowGtk::IsActive() const { + return NativeWidgetGtk::IsActive(); +} + +bool NativeWindowGtk::IsVisible() const { + return GTK_WIDGET_VISIBLE(GetNativeView()); +} + +bool NativeWindowGtk::IsMaximized() const { + return window_state_ & GDK_WINDOW_STATE_MAXIMIZED; +} + +bool NativeWindowGtk::IsMinimized() const { + return window_state_ & GDK_WINDOW_STATE_ICONIFIED; +} + void NativeWindowGtk::SetFullscreen(bool fullscreen) { if (fullscreen) gtk_window_fullscreen(GetNativeWindow()); @@ -310,12 +366,20 @@ NonClientFrameView* NativeWindowGtk::CreateFrameViewForWindow() { return NULL; } +void NativeWindowGtk::SetAlwaysOnTop(bool always_on_top) { + gtk_window_set_keep_above(GetNativeWindow(), always_on_top); +} + void NativeWindowGtk::UpdateFrameAfterFrameChange() { // We currently don't support different frame types on Gtk, so we don't // need to implement this. NOTIMPLEMENTED(); } +gfx::NativeWindow NativeWindowGtk::GetNativeWindow() const { + return GTK_WINDOW(GetNativeView()); +} + bool NativeWindowGtk::ShouldUseNativeFrame() const { return false; } @@ -328,23 +392,6 @@ void NativeWindowGtk::FrameTypeChanged() { } //////////////////////////////////////////////////////////////////////////////// -// NativeWindowGtk, NativeWidgetGtk overrides: - -void NativeWindowGtk::Restore() { - if (IsFullscreen()) - SetFullscreen(false); - else - NativeWidgetGtk::Restore(); -} - -gboolean NativeWindowGtk::OnWindowStateEvent(GtkWidget* widget, - GdkEventWindowState* event) { - if (!(event->new_window_state & GDK_WINDOW_STATE_WITHDRAWN)) - SaveWindowPosition(); - return NativeWidgetGtk::OnWindowStateEvent(widget, event); -} - -//////////////////////////////////////////////////////////////////////////////// // NativeWindowGtk, private: // static @@ -354,6 +401,13 @@ gboolean NativeWindowGtk::CallConfigureEvent(GtkWidget* widget, return window_gtk->OnConfigureEvent(widget, event); } +// static +gboolean NativeWindowGtk::CallWindowStateEvent(GtkWidget* widget, + GdkEventWindowState* event, + NativeWindowGtk* window_gtk) { + return window_gtk->OnWindowStateEvent(widget, event); +} + void NativeWindowGtk::SaveWindowPosition() { // The delegate may have gone away on us. if (!GetWindow()->window_delegate()) diff --git a/views/window/native_window_gtk.h b/views/window/native_window_gtk.h index 56e46da..f45380e 100644 --- a/views/window/native_window_gtk.h +++ b/views/window/native_window_gtk.h @@ -39,6 +39,8 @@ class NativeWindowGtk : public NativeWidgetGtk, public NativeWindow { GdkEventConfigure* event); virtual gboolean OnMotionNotify(GtkWidget* widget, GdkEventMotion* event); virtual void OnSizeAllocate(GtkWidget* widget, GtkAllocation* allocation); + virtual gboolean OnWindowStateEvent(GtkWidget* widget, + GdkEventWindowState* event); virtual gboolean OnLeaveNotify(GtkWidget* widget, GdkEventCrossing* event); virtual void IsActiveChanged(); @@ -63,19 +65,26 @@ class NativeWindowGtk : public NativeWidgetGtk, public NativeWindow { virtual void SetAccessibleState(ui::AccessibilityTypes::State state) OVERRIDE; virtual void SetWindowBounds(const gfx::Rect& bounds, gfx::NativeWindow other_window) OVERRIDE; + virtual void HideWindow() OVERRIDE; + virtual void Activate() OVERRIDE; + virtual void Deactivate() OVERRIDE; + virtual void Maximize() OVERRIDE; + virtual void Minimize() OVERRIDE; + virtual void Restore() OVERRIDE; + virtual bool IsActive() const OVERRIDE; + virtual bool IsVisible() const OVERRIDE; + virtual bool IsMaximized() const OVERRIDE; + virtual bool IsMinimized() const OVERRIDE; virtual void SetFullscreen(bool fullscreen) OVERRIDE; virtual bool IsFullscreen() const OVERRIDE; + virtual void SetAlwaysOnTop(bool always_on_top) OVERRIDE; virtual void SetUseDragFrame(bool use_drag_frame) OVERRIDE; virtual NonClientFrameView* CreateFrameViewForWindow() OVERRIDE; virtual void UpdateFrameAfterFrameChange() OVERRIDE; + virtual gfx::NativeWindow GetNativeWindow() const OVERRIDE; virtual bool ShouldUseNativeFrame() const OVERRIDE; virtual void FrameTypeChanged() OVERRIDE; - // Overridden from NativeWidgetGtk: - virtual void Restore() OVERRIDE; - virtual gboolean OnWindowStateEvent(GtkWidget* widget, - GdkEventWindowState* event) OVERRIDE; - // For the constructor. friend class Window; @@ -85,6 +94,9 @@ class NativeWindowGtk : public NativeWidgetGtk, public NativeWindow { static gboolean CallConfigureEvent(GtkWidget* widget, GdkEventConfigure* event, NativeWindowGtk* window_gtk); + static gboolean CallWindowStateEvent(GtkWidget* widget, + GdkEventWindowState* event, + NativeWindowGtk* window_gtk); // Asks the delegate if any to save the window's location and size. void SaveWindowPosition(); @@ -101,6 +113,9 @@ class NativeWindowGtk : public NativeWidgetGtk, public NativeWindow { // desired implementation before calling |Init|. NonClientView* non_client_view_; + // State of the window, such as fullscreen, hidden... + GdkWindowState window_state_; + // Set to true if the window is in the process of closing. bool window_closed_; diff --git a/views/window/native_window_views.cc b/views/window/native_window_views.cc index de2e2ed..156338b 100644 --- a/views/window/native_window_views.cc +++ b/views/window/native_window_views.cc @@ -92,6 +92,48 @@ void NativeWindowViews::SetWindowBounds(const gfx::Rect& bounds, GetView()->SetBoundsRect(bounds); } +void NativeWindowViews::HideWindow() { + GetView()->SetVisible(false); +} + +void NativeWindowViews::Activate() { + NOTIMPLEMENTED(); +} + +void NativeWindowViews::Deactivate() { + NOTIMPLEMENTED(); +} + +void NativeWindowViews::Maximize() { + NOTIMPLEMENTED(); +} + +void NativeWindowViews::Minimize() { + NOTIMPLEMENTED(); +} + +void NativeWindowViews::Restore() { + NOTIMPLEMENTED(); +} + +bool NativeWindowViews::IsActive() const { + return NativeWidgetViews::IsActive(); +} + +bool NativeWindowViews::IsVisible() const { + return GetView()->IsVisible(); +} + +bool NativeWindowViews::IsMaximized() const { + NOTIMPLEMENTED(); + return false; +} + +bool NativeWindowViews::IsMinimized() const { + NOTIMPLEMENTED(); + return false; +} + void NativeWindowViews::SetFullscreen(bool fullscreen) { } @@ -100,6 +142,9 @@ bool NativeWindowViews::IsFullscreen() const { return false; } +void NativeWindowViews::SetAlwaysOnTop(bool always_on_top) { +} + void NativeWindowViews::SetUseDragFrame(bool use_drag_frame) { } @@ -110,6 +155,10 @@ NonClientFrameView* NativeWindowViews::CreateFrameViewForWindow() { void NativeWindowViews::UpdateFrameAfterFrameChange() { } +gfx::NativeWindow NativeWindowViews::GetNativeWindow() const { + return NULL; +} + bool NativeWindowViews::ShouldUseNativeFrame() const { NOTIMPLEMENTED(); return false; diff --git a/views/window/native_window_views.h b/views/window/native_window_views.h index 83339be..65a4310 100644 --- a/views/window/native_window_views.h +++ b/views/window/native_window_views.h @@ -44,11 +44,23 @@ class NativeWindowViews : public NativeWidgetViews, virtual void SetAccessibleState(ui::AccessibilityTypes::State state) OVERRIDE; virtual void SetWindowBounds(const gfx::Rect& bounds, gfx::NativeWindow other_window) OVERRIDE; + virtual void HideWindow() OVERRIDE; + virtual void Activate() OVERRIDE; + virtual void Deactivate() OVERRIDE; + virtual void Maximize() OVERRIDE; + virtual void Minimize() OVERRIDE; + virtual void Restore() OVERRIDE; + virtual bool IsActive() const OVERRIDE; + virtual bool IsVisible() const OVERRIDE; + virtual bool IsMaximized() const OVERRIDE; + virtual bool IsMinimized() const OVERRIDE; virtual void SetFullscreen(bool fullscreen) OVERRIDE; virtual bool IsFullscreen() const OVERRIDE; + virtual void SetAlwaysOnTop(bool always_on_top) OVERRIDE; virtual void SetUseDragFrame(bool use_drag_frame) OVERRIDE; virtual NonClientFrameView* CreateFrameViewForWindow() OVERRIDE; virtual void UpdateFrameAfterFrameChange() OVERRIDE; + virtual gfx::NativeWindow GetNativeWindow() const OVERRIDE; virtual bool ShouldUseNativeFrame() const OVERRIDE; virtual void FrameTypeChanged() OVERRIDE; diff --git a/views/window/native_window_win.cc b/views/window/native_window_win.cc index c72822a..fed8173 100644 --- a/views/window/native_window_win.cc +++ b/views/window/native_window_win.cc @@ -1175,6 +1175,53 @@ void NativeWindowWin::SetWindowBounds(const gfx::Rect& bounds, kMonitorEdgePadding, 0); } +void NativeWindowWin::HideWindow() { + // We can just call the function implemented by the widget. + Hide(); +} + +void NativeWindowWin::Activate() { + if (IsMinimized()) + ::ShowWindow(GetNativeView(), SW_RESTORE); + ::SetWindowPos(GetNativeView(), HWND_TOP, 0, 0, 0, 0, + SWP_NOSIZE | SWP_NOMOVE); + SetForegroundWindow(GetNativeView()); +} + +void NativeWindowWin::Deactivate() { + HWND hwnd = ::GetNextWindow(GetNativeView(), GW_HWNDNEXT); + if (hwnd) + ::SetForegroundWindow(hwnd); +} + +void NativeWindowWin::Maximize() { + ExecuteSystemMenuCommand(SC_MAXIMIZE); +} + +void NativeWindowWin::Minimize() { + ExecuteSystemMenuCommand(SC_MINIMIZE); +} + +void NativeWindowWin::Restore() { + ExecuteSystemMenuCommand(SC_RESTORE); +} + +bool NativeWindowWin::IsActive() const { + return is_active_; +} + +bool NativeWindowWin::IsVisible() const { + return !!::IsWindowVisible(GetNativeView()); +} + +bool NativeWindowWin::IsMaximized() const { + return !!::IsZoomed(GetNativeView()); +} + +bool NativeWindowWin::IsMinimized() const { + return !!::IsIconic(GetNativeView()); +} + void NativeWindowWin::SetFullscreen(bool fullscreen) { if (fullscreen_ == fullscreen) return; // Nothing to do. @@ -1236,6 +1283,11 @@ bool NativeWindowWin::IsFullscreen() const { return fullscreen_; } +void NativeWindowWin::SetAlwaysOnTop(bool always_on_top) { + ::SetWindowPos(GetNativeView(), always_on_top ? HWND_TOPMOST : HWND_NOTOPMOST, + 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); +} + void NativeWindowWin::SetUseDragFrame(bool use_drag_frame) { if (use_drag_frame) { // Make the frame slightly transparent during the drag operation. @@ -1264,6 +1316,10 @@ void NativeWindowWin::UpdateFrameAfterFrameChange() { ResetWindowRegion(true); } +gfx::NativeWindow NativeWindowWin::GetNativeWindow() const { + return GetNativeView(); +} + bool NativeWindowWin::ShouldUseNativeFrame() const { return NativeWidgetWin::IsAeroGlassEnabled(); } @@ -1298,15 +1354,6 @@ void NativeWindowWin::FrameTypeChanged() { } //////////////////////////////////////////////////////////////////////////////// -// NativeWindowWin, NativeWidgetWin overrides: - -bool NativeWindowWin::IsActive() const { - // TODO(beng): evaluate whether or not this is needed. NativeWidgetWin checks - // active-state with the OS using GetWindowInfo(). - return is_active_; -} - -//////////////////////////////////////////////////////////////////////////////// // NativeWindowWin, private: void NativeWindowWin::RestoreEnabledIfNecessary() { @@ -1409,6 +1456,11 @@ LRESULT NativeWindowWin::CallDefaultNCActivateHandler(BOOL active) { return DefWindowProc(GetNativeView(), WM_NCACTIVATE, active, 0); } +void NativeWindowWin::ExecuteSystemMenuCommand(int command) { + if (command) + SendMessage(GetNativeView(), WM_SYSCOMMAND, command, 0); +} + //////////////////////////////////////////////////////////////////////////////// // NativeWindow, public: diff --git a/views/window/native_window_win.h b/views/window/native_window_win.h index 71eac11..7587832 100644 --- a/views/window/native_window_win.h +++ b/views/window/native_window_win.h @@ -151,17 +151,26 @@ class NativeWindowWin : public NativeWidgetWin, virtual void SetAccessibleState(ui::AccessibilityTypes::State state) OVERRIDE; virtual void SetWindowBounds(const gfx::Rect& bounds, gfx::NativeWindow other_window) OVERRIDE; + virtual void HideWindow() OVERRIDE; + virtual void Activate() OVERRIDE; + virtual void Deactivate() OVERRIDE; + virtual void Maximize() OVERRIDE; + virtual void Minimize() OVERRIDE; + virtual void Restore() OVERRIDE; + virtual bool IsActive() const OVERRIDE; + virtual bool IsVisible() const OVERRIDE; + virtual bool IsMaximized() const OVERRIDE; + virtual bool IsMinimized() const OVERRIDE; virtual void SetFullscreen(bool fullscreen) OVERRIDE; virtual bool IsFullscreen() const OVERRIDE; + virtual void SetAlwaysOnTop(bool always_on_top) OVERRIDE; virtual void SetUseDragFrame(bool use_drag_frame) OVERRIDE; virtual NonClientFrameView* CreateFrameViewForWindow() OVERRIDE; virtual void UpdateFrameAfterFrameChange() OVERRIDE; + virtual gfx::NativeWindow GetNativeWindow() const OVERRIDE; virtual bool ShouldUseNativeFrame() const OVERRIDE; virtual void FrameTypeChanged() OVERRIDE; - // Overridden from NativeWidgetWin: - virtual bool IsActive() const OVERRIDE; - private: // Information saved before going into fullscreen mode, used to restore the // window afterwards. @@ -203,6 +212,9 @@ class NativeWindowWin : public NativeWidgetWin, // flicker. LRESULT CallDefaultNCActivateHandler(BOOL active); + // Executes the specified SC_command. + void ExecuteSystemMenuCommand(int command); + // A delegate implementation that handles events received here. internal::NativeWindowDelegate* delegate_; diff --git a/views/window/window.cc b/views/window/window.cc index 1886aa5..f2d51ee 100644 --- a/views/window/window.cc +++ b/views/window/window.cc @@ -112,15 +112,80 @@ void Window::SetWindowBounds(const gfx::Rect& bounds, native_window_->SetWindowBounds(bounds, other_window); } +void Window::Show() { + native_window_->ShowNativeWindow( + saved_maximized_state_ ? NativeWindow::SHOW_MAXIMIZED + : NativeWindow::SHOW_RESTORED); + // |saved_maximized_state_| only applies the first time the window is shown. + // If we don't reset the value the window will be shown maximized every time + // it is subsequently shown after being hidden. + saved_maximized_state_ = false; +} + void Window::ShowInactive() { native_window_->ShowNativeWindow(NativeWindow::SHOW_INACTIVE); } +void Window::HideWindow() { + native_window_->HideWindow(); +} + void Window::DisableInactiveRendering() { disable_inactive_rendering_ = true; non_client_view_->DisableInactiveRendering(disable_inactive_rendering_); } +void Window::Activate() { + native_window_->Activate(); +} + +void Window::Deactivate() { + native_window_->Deactivate(); +} + +void Window::Close() { + if (window_closed_) { + // It appears we can hit this code path if you close a modal dialog then + // close the last browser before the destructor is hit, which triggers + // invoking Close again. + return; + } + + if (non_client_view_->CanClose()) { + SaveWindowPosition(); + Widget::Close(); + window_closed_ = true; + } +} + +void Window::Maximize() { + native_window_->Maximize(); +} + +void Window::Minimize() { + native_window_->Minimize(); +} + +void Window::Restore() { + native_window_->Restore(); +} + +bool Window::IsActive() const { + return native_window_->IsActive(); +} + +bool Window::IsVisible() const { + return native_window_->IsVisible(); +} + +bool Window::IsMaximized() const { + return native_window_->IsMaximized(); +} + +bool Window::IsMinimized() const { + return native_window_->IsMinimized(); +} + void Window::SetFullscreen(bool fullscreen) { native_window_->SetFullscreen(fullscreen); } @@ -160,6 +225,10 @@ void Window::UpdateWindowIcon() { window_delegate_->GetWindowAppIcon()); } +void Window::SetIsAlwaysOnTop(bool always_on_top) { + native_window_->SetAlwaysOnTop(always_on_top); +} + NonClientFrameView* Window::CreateFrameViewForWindow() { NonClientFrameView* frame_view = native_window_->CreateFrameViewForWindow(); return frame_view ? frame_view : new CustomFrameView(this); @@ -169,6 +238,10 @@ void Window::UpdateFrameAfterFrameChange() { native_window_->UpdateFrameAfterFrameChange(); } +gfx::NativeWindow Window::GetNativeWindow() const { + return native_window_->GetNativeWindow(); +} + bool Window::ShouldUseNativeFrame() const { if (frame_type_ != FRAME_TYPE_DEFAULT) return frame_type_ == FRAME_TYPE_FORCE_NATIVE; @@ -191,34 +264,6 @@ void Window::FrameTypeChanged() { } //////////////////////////////////////////////////////////////////////////////// -// Window, Widget overrides: - -void Window::Show() { - native_window_->ShowNativeWindow( - saved_maximized_state_ ? NativeWindow::SHOW_MAXIMIZED - : NativeWindow::SHOW_RESTORED); - // |saved_maximized_state_| only applies the first time the window is shown. - // If we don't reset the value the window will be shown maximized every time - // it is subsequently shown after being hidden. - saved_maximized_state_ = false; -} - -void Window::Close() { - if (window_closed_) { - // It appears we can hit this code path if you close a modal dialog then - // close the last browser before the destructor is hit, which triggers - // invoking Close again. - return; - } - - if (non_client_view_->CanClose()) { - SaveWindowPosition(); - Widget::Close(); - window_closed_ = true; - } -} - -//////////////////////////////////////////////////////////////////////////////// // Window, internal::NativeWindowDelegate implementation: bool Window::CanActivate() const { diff --git a/views/window/window.h b/views/window/window.h index 669b23d..eb8490a 100644 --- a/views/window/window.h +++ b/views/window/window.h @@ -30,6 +30,15 @@ class WindowDelegate; // // Encapsulates window-like behavior. See WindowDelegate. // +// TODO(beng): Subclass Widget as part of V2. +// +// TODO(beng): Note that this class being non-abstract means that we have a +// violation of Google style in that we are using multiple +// inheritance. The intention is to split this into a separate +// object associated with but not equal to a NativeWidget +// implementation. Multiple inheritance is required for this +// transitional step. +// class Window : public Widget, public internal::NativeWindowDelegate { public: @@ -85,15 +94,50 @@ class Window : public Widget, // monitor. void SetWindowBounds(const gfx::Rect& bounds, gfx::NativeWindow other_window); + // Makes the window visible. + void Show(); + // Like Show(), but does not activate the window. void ShowInactive(); + // Hides the window. This does not delete the window, it just hides it. This + // always hides the window, it is separate from the stack maintained by + // Push/PopForceHidden. + virtual void HideWindow(); + // Prevents the window from being rendered as deactivated the next time it is. // This state is reset automatically as soon as the window becomes activated // again. There is no ability to control the state through this API as this // leads to sync problems. void DisableInactiveRendering(); + // Activates the window, assuming it already exists and is visible. + void Activate(); + + // Deactivates the window, making the next window in the Z order the active + // window. + void Deactivate(); + + // Closes the window, ultimately destroying it. The window hides immediately, + // and is destroyed after a return to the message loop. Close() can be called + // multiple times. + virtual void Close() OVERRIDE; + + // Maximizes/minimizes/restores the window. + void Maximize(); + void Minimize(); + void Restore(); + + // Whether or not the window is currently active. + bool IsActive() const; + + // Whether or not the window is currently visible. + bool IsVisible() const; + + // Whether or not the window is maximized or minimized. + virtual bool IsMaximized() const; + bool IsMinimized() const; + // Accessors for fullscreen state. void SetFullscreen(bool fullscreen); bool IsFullscreen() const; @@ -112,12 +156,18 @@ class Window : public Widget, // Tell the window to update its icon from the delegate. void UpdateWindowIcon(); + // Sets whether or not the window is always-on-top. + void SetIsAlwaysOnTop(bool always_on_top); + // Creates an appropriate NonClientFrameView for this window. virtual NonClientFrameView* CreateFrameViewForWindow(); // Updates the frame after an event caused it to be changed. virtual void UpdateFrameAfterFrameChange(); + // 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_; } @@ -131,10 +181,6 @@ class Window : public Widget, // Tell the window that something caused the frame type to change. void FrameTypeChanged(); - // Overridden from Widget: - virtual void Show() OVERRIDE; - virtual void Close() OVERRIDE; - WindowDelegate* window_delegate() { return const_cast<WindowDelegate*>( const_cast<const Window*>(this)->window_delegate()); |