summaryrefslogtreecommitdiffstats
path: root/views/widget
diff options
context:
space:
mode:
authorben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-27 16:19:51 +0000
committerben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-27 16:19:51 +0000
commit5b6325d8781cbb7b7b703662a4b2b67d620901c0 (patch)
treefc8857298ebb028d6460320b39e67ed99bc1f888 /views/widget
parentf03c9cd35d919838e54df2a698c6a7c53c21b665 (diff)
downloadchromium_src-5b6325d8781cbb7b7b703662a4b2b67d620901c0.zip
chromium_src-5b6325d8781cbb7b7b703662a4b2b67d620901c0.tar.gz
chromium_src-5b6325d8781cbb7b7b703662a4b2b67d620901c0.tar.bz2
Move a bunch of functions from Window onto Widget.
BUG=72040 TEST=none Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=86914 Review URL: http://codereview.chromium.org/7075019 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@87029 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/widget')
-rw-r--r--views/widget/native_widget.h11
-rw-r--r--views/widget/native_widget_gtk.cc64
-rw-r--r--views/widget/native_widget_gtk.h17
-rw-r--r--views/widget/native_widget_views.cc40
-rw-r--r--views/widget/native_widget_views.h11
-rw-r--r--views/widget/native_widget_win.cc55
-rw-r--r--views/widget/native_widget_win.h14
-rw-r--r--views/widget/widget.cc36
-rw-r--r--views/widget/widget.h42
9 files changed, 244 insertions, 46 deletions
diff --git a/views/widget/native_widget.h b/views/widget/native_widget.h
index 2f12fbd..0801971 100644
--- a/views/widget/native_widget.h
+++ b/views/widget/native_widget.h
@@ -142,10 +142,17 @@ 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 410e4de..ef3c7cd 100644
--- a/views/widget/native_widget_gtk.cc
+++ b/views/widget/native_widget_gtk.cc
@@ -284,6 +284,7 @@ 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),
@@ -716,6 +717,8 @@ 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(widget_), "window-state-event",
+ G_CALLBACK(&OnWindowStateEventThunk), this);
tooltip_manager_.reset(new TooltipManagerGtk(this));
@@ -957,13 +960,21 @@ void NativeWidgetGtk::Hide() {
}
}
-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::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::SetAlwaysOnTop(bool on_top) {
@@ -973,13 +984,36 @@ void NativeWidgetGtk::SetAlwaysOnTop(bool on_top) {
gtk_window_set_keep_above(GTK_WINDOW(widget_), on_top);
}
-bool NativeWidgetGtk::IsVisible() const {
- return GTK_WIDGET_VISIBLE(widget_);
+void NativeWidgetGtk::Maximize() {
+ gtk_window_maximize(GetNativeWindow());
}
-bool NativeWidgetGtk::IsActive() const {
- DCHECK(!child_);
- return is_active_;
+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());
+}
+
+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::IsAccessibleWidget() const {
@@ -1361,6 +1395,12 @@ 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 d29fee3..ffc0209 100644
--- a/views/widget/native_widget_gtk.h
+++ b/views/widget/native_widget_gtk.h
@@ -178,10 +178,17 @@ 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,
@@ -245,6 +252,8 @@ 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.
@@ -257,6 +266,10 @@ 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 d1bc2d5..e4dd08d 100644
--- a/views/widget/native_widget_views.cc
+++ b/views/widget/native_widget_views.cc
@@ -177,22 +177,52 @@ void NativeWidgetViews::Hide() {
view_->SetVisible(false);
}
-void NativeWidgetViews::SetOpacity(unsigned char opacity) {
- NOTIMPLEMENTED();
+bool NativeWidgetViews::IsVisible() const {
+ return view_->IsVisible();
}
-void NativeWidgetViews::SetAlwaysOnTop(bool on_top) {
+void NativeWidgetViews::Activate() {
NOTIMPLEMENTED();
}
-bool NativeWidgetViews::IsVisible() const {
- return view_->IsVisible();
+void NativeWidgetViews::Deactivate() {
+ 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();
+}
+
+void NativeWidgetViews::SetOpacity(unsigned char opacity) {
+ NOTIMPLEMENTED();
+}
+
bool NativeWidgetViews::IsAccessibleWidget() const {
NOTIMPLEMENTED();
return false;
diff --git a/views/widget/native_widget_views.h b/views/widget/native_widget_views.h
index 63a5908..be6fbc6 100644
--- a/views/widget/native_widget_views.h
+++ b/views/widget/native_widget_views.h
@@ -66,10 +66,17 @@ 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 3ea4942..36a5d23 100644
--- a/views/widget/native_widget_win.cc
+++ b/views/widget/native_widget_win.cc
@@ -394,25 +394,57 @@ void NativeWidgetWin::Hide() {
}
}
-void NativeWidgetWin::SetOpacity(unsigned char opacity) {
- layered_alpha_ = static_cast<BYTE>(opacity);
+bool NativeWidgetWin::IsVisible() const {
+ return !!::IsWindowVisible(hwnd());
}
-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::Activate() {
+ if (IsMinimized())
+ ::ShowWindow(GetNativeView(), SW_RESTORE);
+ ::SetWindowPos(GetNativeView(), HWND_TOP, 0, 0, 0, 0,
+ SWP_NOSIZE | SWP_NOMOVE);
+ SetForegroundWindow(GetNativeView());
}
-bool NativeWidgetWin::IsVisible() const {
- return !!::IsWindowVisible(hwnd());
+void NativeWidgetWin::Deactivate() {
+ HWND hwnd = ::GetNextWindow(GetNativeView(), GW_HWNDNEXT);
+ if (hwnd)
+ ::SetForegroundWindow(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_;
}
@@ -997,6 +1029,11 @@ 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 8fc0589..f576d96 100644
--- a/views/widget/native_widget_win.h
+++ b/views/widget/native_widget_win.h
@@ -197,10 +197,17 @@ 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,
@@ -387,6 +394,9 @@ 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 8b4e793..4f15d68 100644
--- a/views/widget/widget.cc
+++ b/views/widget/widget.cc
@@ -213,18 +213,46 @@ void Widget::Hide() {
native_widget_->Hide();
}
-bool Widget::IsActive() const {
- return native_widget_->IsActive();
+void Widget::Activate() {
+ native_widget_->Activate();
}
-void Widget::SetOpacity(unsigned char opacity) {
- native_widget_->SetOpacity(opacity);
+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);
+}
+
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 c6f8158..aad6331 100644
--- a/views/widget/widget.h
+++ b/views/widget/widget.h
@@ -16,6 +16,16 @@
#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;
@@ -220,18 +230,37 @@ class Widget : public internal::NativeWidgetDelegate,
void CloseNow();
// Shows or hides the widget, without changing activation state.
- void Show();
+ virtual 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();
@@ -247,10 +276,7 @@ class Widget : public internal::NativeWidgetDelegate,
bool is_secondary_widget() const { return is_secondary_widget_; }
// Returns whether the Widget is visible to the user.
- bool IsVisible() const;
-
- // Returns whether the Widget is the currently active window.
- bool IsActive() const;
+ virtual bool IsVisible() const;
// Returns whether the Widget is customized for accessibility.
bool IsAccessibleWidget() const;