summaryrefslogtreecommitdiffstats
path: root/views
diff options
context:
space:
mode:
authorben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-26 23:42:23 +0000
committerben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-26 23:42:23 +0000
commit6479c267dd32aab3f043aa2d3b2f808505c031ef (patch)
treeb4c1f5aa25fb119ed28338626e947a7f296a02e3 /views
parentb44f5db5391f9865d5950fe88f77dd80e7661ab2 (diff)
downloadchromium_src-6479c267dd32aab3f043aa2d3b2f808505c031ef.zip
chromium_src-6479c267dd32aab3f043aa2d3b2f808505c031ef.tar.gz
chromium_src-6479c267dd32aab3f043aa2d3b2f808505c031ef.tar.bz2
Removes WidgetWin dependency from StatusBubbleViews so that it can compile on Linux.
Requires: - making SetOpacity a cross platform method on Widget, replacing SetLayeredAlpha. - moving Window::SetBounds to Widget - replacing usage of MoveWindow in StatusBubbleViews with call to new SetBounds method. BUG=none TEST=make sure transparency still works for floating widgets like - status bubble, full screen exit bubble, dragged tabs Review URL: http://codereview.chromium.org/113846 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@16948 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views')
-rw-r--r--views/widget/widget.h21
-rw-r--r--views/widget/widget_gtk.cc93
-rw-r--r--views/widget/widget_gtk.h12
-rw-r--r--views/widget/widget_win.cc102
-rw-r--r--views/widget/widget_win.h29
-rw-r--r--views/window/window.h10
-rw-r--r--views/window/window_win.cc6
-rw-r--r--views/window/window_win.h3
8 files changed, 147 insertions, 129 deletions
diff --git a/views/widget/widget.h b/views/widget/widget.h
index b2c3551..efa16c5 100644
--- a/views/widget/widget.h
+++ b/views/widget/widget.h
@@ -46,12 +46,33 @@ class Widget {
// including_frame is ignored.
virtual void GetBounds(gfx::Rect* out, bool including_frame) const = 0;
+ // Sizes and/or places the widget to the specified bounds, size or position.
+ virtual void SetBounds(const gfx::Rect& bounds) = 0;
+
+ // Hides the widget then closes it after a return to the message loop.
+ virtual void Close() = 0;
+
+ // Closes the widget immediately. Compare to |Close|. This will destroy the
+ // window handle associated with this Widget, so should not be called from
+ // any code that expects it to be valid beyond this call.
+ virtual void CloseNow() = 0;
+
+ // Shows or hides the widget, without changing activation state.
+ virtual void Show() = 0;
+ virtual void Hide() = 0;
+
// Returns the gfx::NativeView associated with this Widget.
virtual gfx::NativeView GetNativeView() const = 0;
// Forces a paint of a specified rectangle immediately.
virtual void PaintNow(const gfx::Rect& update_rect) = 0;
+ // 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.
+ virtual void SetOpacity(unsigned char opacity) = 0;
+
// Returns the RootView contained by this Widget.
virtual RootView* GetRootView() = 0;
diff --git a/views/widget/widget_gtk.cc b/views/widget/widget_gtk.cc
index fe347a5..64558ed 100644
--- a/views/widget/widget_gtk.cc
+++ b/views/widget/widget_gtk.cc
@@ -51,6 +51,9 @@ static int GetFlagsForEventButton(const GdkEventButton& event) {
return flags;
}
+////////////////////////////////////////////////////////////////////////////////
+// WidgetGtk, public:
+
WidgetGtk::WidgetGtk(Type type)
: is_window_(false),
type_(type),
@@ -189,6 +192,44 @@ void WidgetGtk::SetContentsView(View* view) {
OnSizeAllocate(widget_, &(widget_->allocation));
}
+////////////////////////////////////////////////////////////////////////////////
+// WidgetGtk, Widget implementation:
+
+void WidgetGtk::GetBounds(gfx::Rect* out, bool including_frame) const {
+ DCHECK(widget_);
+
+ int x = 0, y = 0, w, h;
+ if (GTK_IS_WINDOW(widget_)) {
+ gtk_window_get_position(GTK_WINDOW(widget_), &x, &y);
+ gtk_window_get_size(GTK_WINDOW(widget_), &w, &h);
+ } else {
+ // TODO: make sure this is right. Docs indicate gtk_window_get_position
+ // returns a value useful to the window manager, which may not be the same
+ // as the actual location on the screen.
+ GetWidgetPositionOnScreen(widget_, &x, &y);
+ w = widget_->allocation.width;
+ h = widget_->allocation.height;
+ }
+
+ if (including_frame) {
+ // TODO: Docs indicate it isn't possible to get at this value. We may need
+ // to turn off all decorations so that the frame is always of a 0x0 size.
+ NOTIMPLEMENTED();
+ }
+
+ return out->SetRect(x, y, w, h);
+}
+
+void WidgetGtk::SetBounds(const gfx::Rect& bounds) {
+ if (type_ == TYPE_CHILD) {
+ WidgetGtk* parent_widget = GetViewForNative(gtk_widget_get_parent(widget_));
+ parent_widget->PositionChild(widget_, bounds.x(), bounds.y(),
+ bounds.width(), bounds.height());
+ } else {
+ NOTIMPLEMENTED();
+ }
+}
+
void WidgetGtk::Close() {
if (!widget_)
return; // No need to do anything.
@@ -218,41 +259,6 @@ void WidgetGtk::Hide() {
gtk_widget_hide(widget_);
}
-void WidgetGtk::SetBounds(const gfx::Rect& bounds) {
- if (type_ == TYPE_CHILD) {
- WidgetGtk* parent_widget = GetViewForNative(gtk_widget_get_parent(widget_));
- parent_widget->PositionChild(widget_, bounds.x(), bounds.y(),
- bounds.width(), bounds.height());
- } else {
- NOTIMPLEMENTED();
- }
-}
-
-void WidgetGtk::GetBounds(gfx::Rect* out, bool including_frame) const {
- DCHECK(widget_);
-
- int x = 0, y = 0, w, h;
- if (GTK_IS_WINDOW(widget_)) {
- gtk_window_get_position(GTK_WINDOW(widget_), &x, &y);
- gtk_window_get_size(GTK_WINDOW(widget_), &w, &h);
- } else {
- // TODO: make sure this is right. Docs indicate gtk_window_get_position
- // returns a value useful to the window manager, which may not be the same
- // as the actual location on the screen.
- GetWidgetPositionOnScreen(widget_, &x, &y);
- w = widget_->allocation.width;
- h = widget_->allocation.height;
- }
-
- if (including_frame) {
- // TODO: Docs indicate it isn't possible to get at this value. We may need
- // to turn off all decorations so that the frame is always of a 0x0 size.
- NOTIMPLEMENTED();
- }
-
- return out->SetRect(x, y, w, h);
-}
-
gfx::NativeView WidgetGtk::GetNativeView() const {
return widget_;
}
@@ -262,6 +268,11 @@ void WidgetGtk::PaintNow(const gfx::Rect& update_rect) {
update_rect.width(), update_rect.height());
}
+void WidgetGtk::SetOpacity(unsigned char opacity) {
+ // TODO(port): implement this feature.
+ NOTIMPLEMENTED();
+}
+
RootView* WidgetGtk::GetRootView() {
if (!root_view_.get()) {
// First time the root view is being asked for, create it now.
@@ -304,14 +315,20 @@ Window* WidgetGtk::GetWindow() {
return GetWindowImpl(widget_);
}
+const Window* WidgetGtk::GetWindow() const {
+ return GetWindowImpl(widget_);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// WidgetGtk, MessageLoopForUI::Observer implementation:
+
void WidgetGtk::DidProcessEvent(GdkEvent* event) {
if (root_view_->NeedsPainting(true))
PaintNow(root_view_->GetScheduledPaintRect());
}
-const Window* WidgetGtk::GetWindow() const {
- return GetWindowImpl(widget_);
-}
+////////////////////////////////////////////////////////////////////////////////
+// TODO(beng): organize into sections:
void WidgetGtk::CreateGtkWidget() {
if (type_ == TYPE_CHILD) {
diff --git a/views/widget/widget_gtk.h b/views/widget/widget_gtk.h
index 73d8b7f..7cbc87e 100644
--- a/views/widget/widget_gtk.h
+++ b/views/widget/widget_gtk.h
@@ -59,18 +59,16 @@ class WidgetGtk : public Widget, public MessageLoopForUI::Observer {
virtual void SetContentsView(View* view);
+ // Overridden from Widget:
+ virtual void GetBounds(gfx::Rect* out, bool including_frame) const;
+ virtual void SetBounds(const gfx::Rect& bounds);
virtual void Close();
- void CloseNow();
+ virtual void CloseNow();
virtual void Show();
virtual void Hide();
-
- // Sets the bounds of the widget.
- virtual void SetBounds(const gfx::Rect& bounds);
-
- // Overridden from Widget:
- virtual void GetBounds(gfx::Rect* out, bool including_frame) const;
virtual gfx::NativeView GetNativeView() const;
virtual void PaintNow(const gfx::Rect& update_rect);
+ virtual void SetOpacity(unsigned char opacity);
virtual RootView* GetRootView();
virtual Widget* GetRootWidget() const;
virtual bool IsVisible() const;
diff --git a/views/widget/widget_win.cc b/views/widget/widget_win.cc
index fdb6252..039ab36 100644
--- a/views/widget/widget_win.cc
+++ b/views/widget/widget_win.cc
@@ -253,6 +253,54 @@ void WidgetWin::GetBounds(gfx::Rect* out, bool including_frame) const {
crect.Width(), crect.Height());
}
+void WidgetWin::SetBounds(const gfx::Rect& bounds) {
+ SetWindowPos(NULL, bounds.x(), bounds.y(), bounds.width(), bounds.height(),
+ SWP_NOACTIVATE);
+}
+
+void WidgetWin::Close() {
+ if (!IsWindow())
+ return; // No need to do anything.
+
+ // Let's hide ourselves right away.
+ Hide();
+ if (close_widget_factory_.empty()) {
+ // And we delay the close so that if we are called from an ATL callback,
+ // we don't destroy the window before the callback returned (as the caller
+ // may delete ourselves on destroy and the ATL callback would still
+ // dereference us when the callback returns).
+ MessageLoop::current()->PostTask(FROM_HERE,
+ close_widget_factory_.NewRunnableMethod(
+ &WidgetWin::CloseNow));
+ }
+}
+
+void WidgetWin::CloseNow() {
+ // We may already have been destroyed if the selection resulted in a tab
+ // switch which will have reactivated the browser window and closed us, so
+ // we need to check to see if we're still a window before trying to destroy
+ // ourself.
+ if (IsWindow())
+ DestroyWindow();
+}
+
+void WidgetWin::Show() {
+ if (IsWindow())
+ ShowWindow(SW_SHOWNOACTIVATE);
+}
+
+void WidgetWin::Hide() {
+ if (IsWindow()) {
+ // NOTE: Be careful not to activate any windows here (for example, calling
+ // ShowWindow(SW_HIDE) will automatically activate another window). This
+ // code can be called while a window is being deactivated, and activating
+ // another window will screw up the activation that is already in progress.
+ SetWindowPos(NULL, 0, 0, 0, 0,
+ SWP_HIDEWINDOW | SWP_NOACTIVATE | SWP_NOMOVE |
+ SWP_NOREPOSITION | SWP_NOSIZE | SWP_NOZORDER);
+ }
+}
+
gfx::NativeView WidgetWin::GetNativeView() const {
return hwnd_;
}
@@ -316,6 +364,10 @@ void WidgetWin::PaintNow(const gfx::Rect& update_rect) {
}
}
+void WidgetWin::SetOpacity(unsigned char opacity) {
+ layered_alpha_ = static_cast<BYTE>(opacity);
+}
+
RootView* WidgetWin::GetRootView() {
if (!root_view_.get()) {
// First time the root view is being asked for, create it now.
@@ -359,13 +411,6 @@ const Window* WidgetWin::GetWindow() const {
return GetWindowImpl(hwnd_);
}
-void WidgetWin::SetLayeredAlpha(BYTE layered_alpha) {
- layered_alpha_ = layered_alpha;
-
-// if (hwnd_)
-// UpdateWindowFromContents(contents_->getTopPlatformDevice().getBitmapDC());
-}
-
void WidgetWin::SetUseLayeredBuffer(bool use_layered_buffer) {
if (use_layered_buffer_ == use_layered_buffer)
return;
@@ -407,49 +452,6 @@ RootView* WidgetWin::FindRootView(HWND hwnd) {
return root_view;
}
-void WidgetWin::Close() {
- if (!IsWindow())
- return; // No need to do anything.
-
- // Let's hide ourselves right away.
- Hide();
- if (close_widget_factory_.empty()) {
- // And we delay the close so that if we are called from an ATL callback,
- // we don't destroy the window before the callback returned (as the caller
- // may delete ourselves on destroy and the ATL callback would still
- // dereference us when the callback returns).
- MessageLoop::current()->PostTask(FROM_HERE,
- close_widget_factory_.NewRunnableMethod(
- &WidgetWin::CloseNow));
- }
-}
-
-void WidgetWin::Hide() {
- if (IsWindow()) {
- // NOTE: Be careful not to activate any windows here (for example, calling
- // ShowWindow(SW_HIDE) will automatically activate another window). This
- // code can be called while a window is being deactivated, and activating
- // another window will screw up the activation that is already in progress.
- SetWindowPos(NULL, 0, 0, 0, 0,
- SWP_HIDEWINDOW | SWP_NOACTIVATE | SWP_NOMOVE |
- SWP_NOREPOSITION | SWP_NOSIZE | SWP_NOZORDER);
- }
-}
-
-void WidgetWin::Show() {
- if (IsWindow())
- ShowWindow(SW_SHOWNOACTIVATE);
-}
-
-void WidgetWin::CloseNow() {
- // We may already have been destroyed if the selection resulted in a tab
- // switch which will have reactivated the browser window and closed us, so
- // we need to check to see if we're still a window before trying to destroy
- // ourself.
- if (IsWindow())
- DestroyWindow();
-}
-
///////////////////////////////////////////////////////////////////////////////
// MessageLoop::Observer
diff --git a/views/widget/widget_win.h b/views/widget/widget_win.h
index 3a120db..ebf6bfa 100644
--- a/views/widget/widget_win.h
+++ b/views/widget/widget_win.h
@@ -111,10 +111,6 @@ class WidgetWin : public Widget,
delete_on_destroy_ = delete_on_destroy;
}
- // Sets the initial opacity of a layered window, or updates the window's
- // opacity if it is on the screen.
- void SetLayeredAlpha(BYTE layered_alpha);
-
// See description of use_layered_buffer_ for details.
void SetUseLayeredBuffer(bool use_layered_buffer);
@@ -126,23 +122,6 @@ class WidgetWin : public Widget,
// Returns the RootView associated with the specified HWND (if any).
static RootView* FindRootView(HWND hwnd);
- // Closes the window asynchronously by scheduling a task for it. The window
- // is destroyed as a result.
- // This invokes Hide to hide the window, and schedules a task that
- // invokes CloseNow.
- virtual void Close();
-
- // Hides the window. This does NOT delete the window, it just hides it.
- virtual void Hide();
-
- // Shows the window without changing size/position/activation state.
- virtual void Show();
-
- // Closes the window synchronously. Note that this should not be called from
- // an ATL message callback as it deletes the WidgetWin and ATL will
- // dereference it after the callback is processed.
- void CloseNow();
-
// All classes registered by WidgetWin start with this name.
static const wchar_t* const kBaseClassName;
@@ -234,8 +213,14 @@ class WidgetWin : public Widget,
// Overridden from Widget:
virtual void GetBounds(gfx::Rect* out, bool including_frame) const;
+ virtual void SetBounds(const gfx::Rect& bounds);
+ virtual void Close();
+ virtual void CloseNow();
+ virtual void Show();
+ virtual void Hide();
virtual gfx::NativeView GetNativeView() const;
virtual void PaintNow(const gfx::Rect& update_rect);
+ virtual void SetOpacity(unsigned char opacity);
virtual RootView* GetRootView();
virtual Widget* GetRootWidget() const;
virtual bool IsVisible() const;
@@ -514,6 +499,8 @@ class WidgetWin : public Widget,
// is true.
virtual bool ReleaseCaptureOnMouseReleased() { return true; }
+ // Creates the RootView to be used within this Widget. Can be overridden to
+ // create specialized RootView implementations.
virtual RootView* CreateRootView();
// Returns true if this WidgetWin is opaque.
diff --git a/views/window/window.h b/views/window/window.h
index bb618ed..b5a1f56 100644
--- a/views/window/window.h
+++ b/views/window/window.h
@@ -50,12 +50,10 @@ class Window {
// Retrieves the restored bounds for the window.
virtual gfx::Rect GetNormalBounds() const = 0;
- // Sizes and/or places the window to the specified bounds, size or position.
- virtual void SetBounds(const gfx::Rect& bounds) = 0;
-
- // As above, except the window is inserted after |other_window| in the window
- // Z-order. If this window is not yet visible, other_window's monitor is used
- // as the constraining rectangle, rather than this window's monitor.
+ // Sets the Window's bounds. The window is inserted after |other_window| in
+ // the window Z-order. If this window is not yet visible, other_window's
+ // monitor is used as the constraining rectangle, rather than this window's
+ // monitor.
virtual void SetBounds(const gfx::Rect& bounds,
gfx::NativeWindow other_window) = 0;
diff --git a/views/window/window_win.cc b/views/window/window_win.cc
index 2ba4797..3e52871 100644
--- a/views/window/window_win.cc
+++ b/views/window/window_win.cc
@@ -127,10 +127,6 @@ gfx::Rect WindowWin::GetNormalBounds() const {
return gfx::Rect(wp.rcNormalPosition);
}
-void WindowWin::SetBounds(const gfx::Rect& bounds) {
- SetBounds(bounds, NULL);
-}
-
void WindowWin::SetBounds(const gfx::Rect& bounds,
gfx::NativeWindow other_window) {
win_util::SetChildBounds(GetNativeView(), GetParent(), other_window, bounds,
@@ -1213,7 +1209,7 @@ void WindowWin::SetInitialBounds(const gfx::Rect& create_bounds) {
SizeWindowToDefault();
} else {
// Use the supplied initial bounds.
- SetBounds(create_bounds);
+ SetBounds(create_bounds, NULL);
}
}
}
diff --git a/views/window/window_win.h b/views/window/window_win.h
index ddc2f21..5be2319 100644
--- a/views/window/window_win.h
+++ b/views/window/window_win.h
@@ -50,10 +50,9 @@ class WindowWin : public WidgetWin,
focus_on_creation_ = focus_on_creation;
}
- // Window overrides:
+ // Overridden from Window:
virtual gfx::Rect GetBounds() const;
virtual gfx::Rect GetNormalBounds() const;
- virtual void SetBounds(const gfx::Rect& bounds);
virtual void SetBounds(const gfx::Rect& bounds,
gfx::NativeWindow other_window);
virtual void Show();