summaryrefslogtreecommitdiffstats
path: root/views
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-08 15:51:47 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-08 15:51:47 +0000
commit62dd7ea6f2317cf4dc388bc6f8f71c4162386ca0 (patch)
treeeb85d78c357c8eb27d4818353ab123c970292a89 /views
parent8ddeef5ccac30b41975fedd60a24f414325326a0 (diff)
downloadchromium_src-62dd7ea6f2317cf4dc388bc6f8f71c4162386ca0.zip
chromium_src-62dd7ea6f2317cf4dc388bc6f8f71c4162386ca0.tar.gz
chromium_src-62dd7ea6f2317cf4dc388bc6f8f71c4162386ca0.tar.bz2
Adds Window::MoveChildToFront, with surrounding changes.
BUG=102580 102578 TEST=none R=ben@chromium.org Review URL: http://codereview.chromium.org/8477019 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@109032 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views')
-rw-r--r--views/widget/native_widget_aura.cc13
-rw-r--r--views/widget/native_widget_aura.h2
-rw-r--r--views/widget/native_widget_gtk.cc8
-rw-r--r--views/widget/native_widget_gtk.h2
-rw-r--r--views/widget/native_widget_private.h2
-rw-r--r--views/widget/native_widget_views.cc6
-rw-r--r--views/widget/native_widget_views.h2
-rw-r--r--views/widget/native_widget_wayland.cc6
-rw-r--r--views/widget/native_widget_wayland.h2
-rw-r--r--views/widget/native_widget_win.cc101
-rw-r--r--views/widget/native_widget_win.h13
-rw-r--r--views/widget/native_widget_win_unittest.cc47
-rw-r--r--views/widget/widget.cc16
-rw-r--r--views/widget/widget.h10
14 files changed, 20 insertions, 210 deletions
diff --git a/views/widget/native_widget_aura.cc b/views/widget/native_widget_aura.cc
index 400b457..d8358ee 100644
--- a/views/widget/native_widget_aura.cc
+++ b/views/widget/native_widget_aura.cc
@@ -335,20 +335,13 @@ void NativeWidgetAura::SetSize(const gfx::Size& size) {
window_->SetBounds(gfx::Rect(window_->bounds().origin(), size));
}
-void NativeWidgetAura::SetBoundsConstrained(const gfx::Rect& bounds,
- Widget* other_widget) {
- // http://crbug.com/102580
- NOTIMPLEMENTED();
-}
-
void NativeWidgetAura::MoveAbove(gfx::NativeView native_view) {
- // http://crbug.com/102578
- NOTIMPLEMENTED();
+ if (window_->parent() && window_->parent() == native_view->parent())
+ window_->parent()->MoveChildAbove(window_, native_view);
}
void NativeWidgetAura::MoveToTop() {
- // http://crbug.com/102578
- NOTIMPLEMENTED();
+ window_->parent()->MoveChildToFront(window_);
}
void NativeWidgetAura::SetShape(gfx::NativeRegion region) {
diff --git a/views/widget/native_widget_aura.h b/views/widget/native_widget_aura.h
index e257a2d..c93c61b 100644
--- a/views/widget/native_widget_aura.h
+++ b/views/widget/native_widget_aura.h
@@ -79,8 +79,6 @@ class VIEWS_EXPORT NativeWidgetAura : public internal::NativeWidgetPrivate,
virtual gfx::Rect GetRestoredBounds() const OVERRIDE;
virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE;
virtual void SetSize(const gfx::Size& size) OVERRIDE;
- virtual void SetBoundsConstrained(const gfx::Rect& bounds,
- Widget* other_widget) OVERRIDE;
virtual void MoveAbove(gfx::NativeView native_view) OVERRIDE;
virtual void MoveToTop() OVERRIDE;
virtual void SetShape(gfx::NativeRegion shape) OVERRIDE;
diff --git a/views/widget/native_widget_gtk.cc b/views/widget/native_widget_gtk.cc
index 37e0752..b67bad9 100644
--- a/views/widget/native_widget_gtk.cc
+++ b/views/widget/native_widget_gtk.cc
@@ -1028,7 +1028,7 @@ void NativeWidgetGtk::CenterWindow(const gfx::Size& size) {
gfx::Rect bounds(center_rect.x() + (center_rect.width() - size.width()) / 2,
center_rect.y() + (center_rect.height() - size.height()) / 2,
size.width(), size.height());
- SetBoundsConstrained(bounds, NULL);
+ GetWidget()->SetBoundsConstrained(bounds);
}
void NativeWidgetGtk::GetWindowPlacement(
@@ -1144,12 +1144,6 @@ void NativeWidgetGtk::SetSize(const gfx::Size& size) {
}
}
-void NativeWidgetGtk::SetBoundsConstrained(const gfx::Rect& bounds,
- Widget* other_widget) {
- // We apparently don't care about |other_widget|.
- SetBounds(bounds);
-}
-
void NativeWidgetGtk::MoveAbove(gfx::NativeView native_view) {
ui::StackPopupWindow(GetNativeView(), native_view);
}
diff --git a/views/widget/native_widget_gtk.h b/views/widget/native_widget_gtk.h
index 80db70e..1c85f0e 100644
--- a/views/widget/native_widget_gtk.h
+++ b/views/widget/native_widget_gtk.h
@@ -186,8 +186,6 @@ class VIEWS_EXPORT NativeWidgetGtk : public internal::NativeWidgetPrivate,
virtual gfx::Rect GetRestoredBounds() const OVERRIDE;
virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE;
virtual void SetSize(const gfx::Size& size) OVERRIDE;
- virtual void SetBoundsConstrained(const gfx::Rect& bounds,
- Widget* other_widget) OVERRIDE;
virtual void MoveAbove(gfx::NativeView native_view) OVERRIDE;
virtual void MoveToTop() OVERRIDE;
virtual void SetShape(gfx::NativeRegion shape) OVERRIDE;
diff --git a/views/widget/native_widget_private.h b/views/widget/native_widget_private.h
index d604941..40d8a59 100644
--- a/views/widget/native_widget_private.h
+++ b/views/widget/native_widget_private.h
@@ -167,8 +167,6 @@ class VIEWS_EXPORT NativeWidgetPrivate : public NativeWidget,
virtual gfx::Rect GetRestoredBounds() const = 0;
virtual void SetBounds(const gfx::Rect& bounds) = 0;
virtual void SetSize(const gfx::Size& size) = 0;
- virtual void SetBoundsConstrained(const gfx::Rect& bounds,
- Widget* other_widget) = 0;
virtual void MoveAbove(gfx::NativeView native_view) = 0;
virtual void MoveToTop() = 0;
virtual void SetShape(gfx::NativeRegion shape) = 0;
diff --git a/views/widget/native_widget_views.cc b/views/widget/native_widget_views.cc
index 3d1c263..a7ab988 100644
--- a/views/widget/native_widget_views.cc
+++ b/views/widget/native_widget_views.cc
@@ -362,12 +362,6 @@ void NativeWidgetViews::SetSize(const gfx::Size& size) {
view_->SetSize(size);
}
-void NativeWidgetViews::SetBoundsConstrained(const gfx::Rect& bounds,
- Widget* other_widget) {
- // TODO(beng): honor other_widget.
- SetBounds(bounds);
-}
-
void NativeWidgetViews::MoveAbove(gfx::NativeView native_view) {
NOTIMPLEMENTED();
}
diff --git a/views/widget/native_widget_views.h b/views/widget/native_widget_views.h
index ee3aaa9..caf48dd 100644
--- a/views/widget/native_widget_views.h
+++ b/views/widget/native_widget_views.h
@@ -101,8 +101,6 @@ class VIEWS_EXPORT NativeWidgetViews : public internal::NativeWidgetPrivate {
virtual gfx::Rect GetRestoredBounds() const OVERRIDE;
virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE;
virtual void SetSize(const gfx::Size& size) OVERRIDE;
- virtual void SetBoundsConstrained(const gfx::Rect& bounds,
- Widget* other_widget) OVERRIDE;
virtual void MoveAbove(gfx::NativeView native_view) OVERRIDE;
virtual void MoveToTop() OVERRIDE;
virtual void SetShape(gfx::NativeRegion shape) OVERRIDE;
diff --git a/views/widget/native_widget_wayland.cc b/views/widget/native_widget_wayland.cc
index d85db33..2be625a 100644
--- a/views/widget/native_widget_wayland.cc
+++ b/views/widget/native_widget_wayland.cc
@@ -319,12 +319,6 @@ void NativeWidgetWayland::SetSize(const gfx::Size& size) {
SetBounds(new_alloc);
}
-void NativeWidgetWayland::SetBoundsConstrained(const gfx::Rect& bounds,
- Widget* other_widget) {
- // TODO(dnicoara) Need to take into account |other_widget|.
- SetBounds(bounds);
-}
-
void NativeWidgetWayland::MoveAbove(gfx::NativeView native_view) {
NOTIMPLEMENTED();
}
diff --git a/views/widget/native_widget_wayland.h b/views/widget/native_widget_wayland.h
index ee2f003..8431588 100644
--- a/views/widget/native_widget_wayland.h
+++ b/views/widget/native_widget_wayland.h
@@ -91,8 +91,6 @@ class NativeWidgetWayland : public internal::NativeWidgetPrivate,
virtual gfx::Rect GetRestoredBounds() const OVERRIDE;
virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE;
virtual void SetSize(const gfx::Size& size) OVERRIDE;
- virtual void SetBoundsConstrained(const gfx::Rect& bounds,
- Widget* other_widget) OVERRIDE;
virtual void MoveAbove(gfx::NativeView native_view) OVERRIDE;
virtual void MoveToTop() OVERRIDE;
virtual void SetShape(gfx::NativeRegion shape) OVERRIDE;
diff --git a/views/widget/native_widget_win.cc b/views/widget/native_widget_win.cc
index 14bc426..e31196e 100644
--- a/views/widget/native_widget_win.cc
+++ b/views/widget/native_widget_win.cc
@@ -55,47 +55,6 @@ using ui::ViewProp;
namespace views {
-namespace internal {
-
-void EnsureRectIsVisibleInRect(const gfx::Rect& parent_rect,
- gfx::Rect* child_rect,
- int padding) {
- DCHECK(child_rect);
-
- // We use padding here because it allows some of the original web page to
- // bleed through around the edges.
- int twice_padding = padding * 2;
-
- // FIRST, clamp width and height so we don't open child windows larger than
- // the containing parent.
- if (child_rect->width() > (parent_rect.width() + twice_padding))
- child_rect->set_width(std::max(0, parent_rect.width() - twice_padding));
- if (child_rect->height() > parent_rect.height() + twice_padding)
- child_rect->set_height(std::max(0, parent_rect.height() - twice_padding));
-
- // SECOND, clamp x,y position to padding,padding so we don't position child
- // windows in hyperspace.
- // TODO(mpcomplete): I don't see what the second check in each 'if' does that
- // isn't handled by the LAST set of 'ifs'. Maybe we can remove it.
- if (child_rect->x() < parent_rect.x() ||
- child_rect->x() > parent_rect.right()) {
- child_rect->set_x(parent_rect.x() + padding);
- }
- if (child_rect->y() < parent_rect.y() ||
- child_rect->y() > parent_rect.bottom()) {
- child_rect->set_y(parent_rect.y() + padding);
- }
-
- // LAST, nudge the window back up into the client area if its x,y position is
- // within the parent bounds but its width/height place it off-screen.
- if (child_rect->bottom() > parent_rect.bottom())
- child_rect->set_y(parent_rect.bottom() - child_rect->height() - padding);
- if (child_rect->right() > parent_rect.right())
- child_rect->set_x(parent_rect.right() - child_rect->width() - padding);
-}
-
-} // namespace internal
-
namespace {
// Get the source HWND of the specified message. Depending on the message, the
@@ -161,54 +120,6 @@ bool DidClientAreaSizeChange(const WINDOWPOS* window_pos) {
window_pos->flags & SWP_FRAMECHANGED;
}
-// Ensures that the child window stays within the boundaries of the parent
-// before setting its bounds. If |parent_window| is NULL, the bounds of the
-// parent are assumed to be the bounds of the monitor that |child_window| is
-// nearest to. If |child_window| isn't visible yet and |insert_after_window|
-// is non-NULL and visible, the monitor |insert_after_window| is on is used
-// as the parent bounds instead.
-// TODO(beng): This function could easily not be so windowsy, deal with Widgets
-// instead of HWNDs, and move to Widget instead of NativeWidget and
-// then miraculously also work on Linux.
-void SetChildBounds(HWND child_window,
- HWND parent_window,
- HWND insert_after_window,
- const gfx::Rect& bounds,
- int padding,
- unsigned long flags) {
- DCHECK(IsWindow(child_window));
-
- // First figure out the bounds of the parent.
- RECT parent_rect = {0};
- if (parent_window) {
- GetClientRect(parent_window, &parent_rect);
- } else {
- // If there is no parent, we consider the bounds of the monitor the window
- // is on to be the parent bounds.
-
- // If the child_window isn't visible yet and we've been given a valid,
- // visible insert after window, use that window to locate the correct
- // monitor instead.
- HWND window = child_window;
- if (!IsWindowVisible(window) && IsWindow(insert_after_window) &&
- IsWindowVisible(insert_after_window))
- window = insert_after_window;
-
- gfx::Rect work_area =
- gfx::Screen::GetMonitorWorkAreaNearestPoint(bounds.origin());
- if (!work_area.IsEmpty())
- parent_rect = work_area.ToRECT();
- }
-
- gfx::Rect actual_bounds = bounds;
- internal::EnsureRectIsVisibleInRect(gfx::Rect(parent_rect), &actual_bounds,
- padding);
-
- SetWindowPos(child_window, insert_after_window, actual_bounds.x(),
- actual_bounds.y(), actual_bounds.width(),
- actual_bounds.height(), flags);
-}
-
// Callback used to notify child windows that the top level window received a
// DWMCompositionChanged message.
BOOL CALLBACK SendDwmCompositionChanged(HWND window, LPARAM param) {
@@ -296,11 +207,6 @@ const char* const kNativeWidgetKey = "__VIEWS_NATIVE_WIDGET__";
// listening for MSAA events.
const int kCustomObjectID = 1;
-// If the hung renderer warning doesn't fit on screen, the amount of padding to
-// be left between the edge of the window and the edge of the nearest monitor,
-// after the window is nudged back on screen. Pixels.
-const int kMonitorEdgePadding = 10;
-
const int kDragFrameWindowAlpha = 200;
} // namespace
@@ -806,13 +712,6 @@ void NativeWidgetWin::SetSize(const gfx::Size& size) {
SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOMOVE);
}
-void NativeWidgetWin::SetBoundsConstrained(const gfx::Rect& bounds,
- Widget* other_widget) {
- SetChildBounds(GetNativeView(), GetParent(),
- other_widget ? other_widget->GetNativeView() : NULL,
- bounds, kMonitorEdgePadding, 0);
-}
-
void NativeWidgetWin::MoveAbove(gfx::NativeView native_view) {
SetWindowPos(native_view, 0, 0, 0, 0,
SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
diff --git a/views/widget/native_widget_win.h b/views/widget/native_widget_win.h
index 5c4cf59..82ae23f7 100644
--- a/views/widget/native_widget_win.h
+++ b/views/widget/native_widget_win.h
@@ -44,17 +44,6 @@ class DropTargetWin;
class RootView;
class TooltipManagerWin;
-namespace internal {
-class NativeWidgetDelegate;
-
-// This is exposed only for testing
-// Adjusts the value of |child_rect| if necessary to ensure that it is
-// completely visible within |parent_rect|.
-VIEWS_EXPORT void EnsureRectIsVisibleInRect(const gfx::Rect& parent_rect,
- gfx::Rect* child_rect,
- int padding);
-} // namespace internal
-
// These two messages aren't defined in winuser.h, but they are sent to windows
// with captions. They appear to paint the window caption and frame.
// Unfortunately if you override the standard non-client rendering as we do
@@ -231,8 +220,6 @@ class VIEWS_EXPORT NativeWidgetWin : public ui::WindowImpl,
virtual gfx::Rect GetRestoredBounds() const OVERRIDE;
virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE;
virtual void SetSize(const gfx::Size& size) OVERRIDE;
- virtual void SetBoundsConstrained(const gfx::Rect& bounds,
- Widget* other_widget) OVERRIDE;
virtual void MoveAbove(gfx::NativeView native_view) OVERRIDE;
virtual void MoveToTop() OVERRIDE;
virtual void SetShape(gfx::NativeRegion shape) OVERRIDE;
diff --git a/views/widget/native_widget_win_unittest.cc b/views/widget/native_widget_win_unittest.cc
index d53ee59..f2465f4 100644
--- a/views/widget/native_widget_win_unittest.cc
+++ b/views/widget/native_widget_win_unittest.cc
@@ -82,52 +82,5 @@ TEST_F(NativeWidgetWinTest, SetBoundsForZoomedWindow) {
window2->CloseNow();
}
-TEST_F(NativeWidgetWinTest, EnsureRectIsVisibleInRect) {
- gfx::Rect parent_rect(0, 0, 500, 400);
-
- {
- // Child rect x < 0
- gfx::Rect child_rect(-50, 20, 100, 100);
- internal::EnsureRectIsVisibleInRect(parent_rect, &child_rect, 10);
- EXPECT_EQ(gfx::Rect(10, 20, 100, 100), child_rect);
- }
-
- {
- // Child rect y < 0
- gfx::Rect child_rect(20, -50, 100, 100);
- internal::EnsureRectIsVisibleInRect(parent_rect, &child_rect, 10);
- EXPECT_EQ(gfx::Rect(20, 10, 100, 100), child_rect);
- }
-
- {
- // Child rect right > parent_rect.right
- gfx::Rect child_rect(450, 20, 100, 100);
- internal::EnsureRectIsVisibleInRect(parent_rect, &child_rect, 10);
- EXPECT_EQ(gfx::Rect(390, 20, 100, 100), child_rect);
- }
-
- {
- // Child rect bottom > parent_rect.bottom
- gfx::Rect child_rect(20, 350, 100, 100);
- internal::EnsureRectIsVisibleInRect(parent_rect, &child_rect, 10);
- EXPECT_EQ(gfx::Rect(20, 290, 100, 100), child_rect);
- }
-
- {
- // Child rect width > parent_rect.width
- gfx::Rect child_rect(20, 20, 700, 100);
- internal::EnsureRectIsVisibleInRect(parent_rect, &child_rect, 10);
- EXPECT_EQ(gfx::Rect(20, 20, 480, 100), child_rect);
- }
-
- {
- // Child rect height > parent_rect.height
- gfx::Rect child_rect(20, 20, 100, 700);
- internal::EnsureRectIsVisibleInRect(parent_rect, &child_rect, 10);
- EXPECT_EQ(gfx::Rect(20, 20, 100, 380), child_rect);
- }
-}
-
-
} // namespace
} // namespace views
diff --git a/views/widget/widget.cc b/views/widget/widget.cc
index 029b920..c7fb360 100644
--- a/views/widget/widget.cc
+++ b/views/widget/widget.cc
@@ -11,6 +11,7 @@
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/compositor/compositor.h"
#include "ui/gfx/compositor/layer.h"
+#include "ui/gfx/screen.h"
#include "views/controls/menu/menu_controller.h"
#include "views/focus/focus_manager.h"
#include "views/focus/focus_manager_factory.h"
@@ -429,9 +430,16 @@ void Widget::SetSize(const gfx::Size& size) {
native_widget_->SetSize(size);
}
-void Widget::SetBoundsConstrained(const gfx::Rect& bounds,
- Widget* other_widget) {
- native_widget_->SetBoundsConstrained(bounds, other_widget);
+void Widget::SetBoundsConstrained(const gfx::Rect& bounds) {
+ gfx::Rect work_area =
+ gfx::Screen::GetMonitorWorkAreaNearestPoint(bounds.origin());
+ if (work_area.IsEmpty()) {
+ SetBounds(bounds);
+ } else {
+ // Inset the work area slightly.
+ work_area.Inset(10, 10, 10, 10);
+ SetBounds(work_area.AdjustToFit(bounds));
+ }
}
void Widget::MoveAboveWidget(Widget* widget) {
@@ -1153,7 +1161,7 @@ void Widget::SetInitialBounds(const gfx::Rect& bounds) {
native_widget_->CenterWindow(non_client_view_->GetPreferredSize());
} else {
// Use the supplied initial bounds.
- SetBoundsConstrained(bounds, NULL);
+ SetBoundsConstrained(bounds);
}
}
}
diff --git a/views/widget/widget.h b/views/widget/widget.h
index 3429074..0a4d59e 100644
--- a/views/widget/widget.h
+++ b/views/widget/widget.h
@@ -297,12 +297,10 @@ class VIEWS_EXPORT Widget : public internal::NativeWidgetDelegate,
void SetBounds(const gfx::Rect& bounds);
void SetSize(const gfx::Size& size);
- // Like SetBounds(), but ensures the Widget is fully visible within the bounds
- // of its parent. If the Widget has no parent, it is centered within the
- // bounds of its screen if it is visible, or |other_widget|'s screen if it is
- // not.
- void SetBoundsConstrained(const gfx::Rect& bounds,
- Widget* other_widget);
+ // Like SetBounds(), but ensures the Widget is fully visible on screen,
+ // resizing and/or repositioning as necessary. This is only useful for
+ // non-child widgets.
+ void SetBoundsConstrained(const gfx::Rect& bounds);
// Places the widget in front of the specified widget in z-order.
void MoveAboveWidget(Widget* widget);