summaryrefslogtreecommitdiffstats
path: root/ui/views
diff options
context:
space:
mode:
authormsw@chromium.org <msw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-05 07:31:53 +0000
committermsw@chromium.org <msw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-05 07:31:53 +0000
commit5238e9d7fe37e672f3546c451a5dd973b37c684d (patch)
tree0d9763d8ce2770b99c9077c4b1050ba2e39633af /ui/views
parentad03dec49652b585bd1a92963e86a30b59cb8449 (diff)
downloadchromium_src-5238e9d7fe37e672f3546c451a5dd973b37c684d.zip
chromium_src-5238e9d7fe37e672f3546c451a5dd973b37c684d.tar.gz
chromium_src-5238e9d7fe37e672f3546c451a5dd973b37c684d.tar.bz2
Do not allow Views new-dialog-style windows to be resized.
Continuation of https://codereview.chromium.org/15894025/ Allow the top-left to show the system menu on left-click. Allow the titlebar to show the system menu on right-click. Allow dragging dialogs from the titlebar (for now). Expand BubbleFrameViewTest.NonClientHitTest and support. Add dialog_delegate_unittest.cc and DialogTest.HitTest. Remove unnecessary CreateApplicationShortcutView overrides. BUG=166075,244559,244676,246777 TEST=Views new-dialog-style windows cannot be resized, but do show the system menu and allow dragging (for now). R=sky@chromium.org Review URL: https://chromiumcodereview.appspot.com/16361009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@204190 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/views')
-rw-r--r--ui/views/bubble/bubble_frame_view.cc20
-rw-r--r--ui/views/bubble/bubble_frame_view_unittest.cc90
-rw-r--r--ui/views/views.gyp1
-rw-r--r--ui/views/window/dialog_delegate_unittest.cc62
4 files changed, 117 insertions, 56 deletions
diff --git a/ui/views/bubble/bubble_frame_view.cc b/ui/views/bubble/bubble_frame_view.cc
index c0fb749..7b011c5 100644
--- a/ui/views/bubble/bubble_frame_view.cc
+++ b/ui/views/bubble/bubble_frame_view.cc
@@ -94,14 +94,18 @@ int BubbleFrameView::NonClientHitTest(const gfx::Point& point) {
return HTNOWHERE;
if (close_->visible() && close_->GetMirroredBounds().Contains(point))
return HTCLOSE;
- if (!GetWidget()->widget_delegate()->CanResize())
- return GetWidget()->client_view()->NonClientHitTest(point);
-
- const int size = bubble_border_->GetBorderThickness() + 4;
- const int hit = GetHTComponentForFrame(point, size, size, size, size, true);
- if (hit == HTNOWHERE && point.y() < title_->bounds().bottom())
- return HTCAPTION;
- return hit;
+
+ // Allow dialogs to show the system menu and be dragged.
+ if (GetWidget()->widget_delegate()->AsDialogDelegate()) {
+ gfx::Rect sys_rect(0, 0, title_->x(), title_->y());
+ sys_rect.set_origin(gfx::Point(GetMirroredXForRect(sys_rect), 0));
+ if (sys_rect.Contains(point))
+ return HTSYSMENU;
+ if (point.y() < title_->bounds().bottom())
+ return HTCAPTION;
+ }
+
+ return GetWidget()->client_view()->NonClientHitTest(point);
}
void BubbleFrameView::GetWindowMask(const gfx::Size& size,
diff --git a/ui/views/bubble/bubble_frame_view_unittest.cc b/ui/views/bubble/bubble_frame_view_unittest.cc
index bcb853f..cf9f098 100644
--- a/ui/views/bubble/bubble_frame_view_unittest.cc
+++ b/ui/views/bubble/bubble_frame_view_unittest.cc
@@ -17,40 +17,35 @@ typedef ViewsTestBase BubbleFrameViewTest;
namespace {
const BubbleBorder::Arrow kArrow = BubbleBorder::TOP_LEFT;
-const int kBubbleWidth = 200;
-const int kBubbleHeight = 200;
const SkColor kColor = SK_ColorRED;
const int kMargin = 6;
-class SizedBubbleDelegateView : public BubbleDelegateView {
+class TestBubbleDelegateView : public BubbleDelegateView {
public:
- SizedBubbleDelegateView(View* anchor_view);
- virtual ~SizedBubbleDelegateView();
+ explicit TestBubbleDelegateView(View* anchor_view)
+ : BubbleDelegateView(anchor_view, kArrow) {}
+ virtual ~TestBubbleDelegateView() {}
- // View overrides:
- virtual gfx::Size GetPreferredSize() OVERRIDE;
+ // BubbleDelegateView overrides:
+ virtual gfx::Size GetPreferredSize() OVERRIDE { return gfx::Size(200, 200); }
- private:
- DISALLOW_COPY_AND_ASSIGN(SizedBubbleDelegateView);
+private:
+ DISALLOW_COPY_AND_ASSIGN(TestBubbleDelegateView);
};
-SizedBubbleDelegateView::SizedBubbleDelegateView(View* anchor_view)
- : BubbleDelegateView(anchor_view, BubbleBorder::TOP_LEFT) {
-}
-
-SizedBubbleDelegateView::~SizedBubbleDelegateView() {}
-
-gfx::Size SizedBubbleDelegateView::GetPreferredSize() {
- return gfx::Size(kBubbleWidth, kBubbleHeight);
-}
-
class TestBubbleFrameView : public BubbleFrameView {
public:
- TestBubbleFrameView();
- virtual ~TestBubbleFrameView();
-
- protected:
- virtual gfx::Rect GetMonitorBounds(const gfx::Rect& rect) OVERRIDE;
+ TestBubbleFrameView()
+ : BubbleFrameView(gfx::Insets(kMargin, kMargin, kMargin, kMargin)),
+ monitor_bounds_(gfx::Rect(0, 0, 1000, 1000)) {
+ SetBubbleBorder(new BubbleBorder(kArrow, BubbleBorder::NO_SHADOW, kColor));
+ }
+ virtual ~TestBubbleFrameView() {}
+
+ // BubbleDelegateView overrides:
+ virtual gfx::Rect GetMonitorBounds(const gfx::Rect& rect) OVERRIDE {
+ return monitor_bounds_;
+ }
private:
gfx::Rect monitor_bounds_;
@@ -58,18 +53,6 @@ class TestBubbleFrameView : public BubbleFrameView {
DISALLOW_COPY_AND_ASSIGN(TestBubbleFrameView);
};
-TestBubbleFrameView::TestBubbleFrameView()
- : BubbleFrameView(gfx::Insets(kMargin, kMargin, kMargin, kMargin)),
- monitor_bounds_(gfx::Rect(0, 0, 1000, 1000)) {
- SetBubbleBorder(new BubbleBorder(kArrow, BubbleBorder::NO_SHADOW, kColor));
-}
-
-TestBubbleFrameView::~TestBubbleFrameView() {}
-
-gfx::Rect TestBubbleFrameView::GetMonitorBounds(const gfx::Rect& rect) {
- return monitor_bounds_;
-}
-
} // namespace
TEST_F(BubbleFrameViewTest, GetBoundsForClientView) {
@@ -85,24 +68,35 @@ TEST_F(BubbleFrameViewTest, GetBoundsForClientView) {
}
TEST_F(BubbleFrameViewTest, NonClientHitTest) {
- // Create the anchor and parent widgets.
+ // Create the anchor view, its parent widget is needed on Aura.
Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW);
params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
scoped_ptr<Widget> anchor_widget(new Widget);
anchor_widget->Init(params);
anchor_widget->Show();
- BubbleDelegateView* delegate =
- new SizedBubbleDelegateView(anchor_widget->GetContentsView());
- Widget* widget(BubbleDelegateView::CreateBubble(delegate));
- widget->Show();
- gfx::Point kPtInBound(100, 100);
- gfx::Point kPtOutsideBound(1000, 1000);
- BubbleFrameView* bubble_frame_view = delegate->GetBubbleFrameView();
- EXPECT_EQ(HTCLIENT, bubble_frame_view->NonClientHitTest(kPtInBound));
- EXPECT_EQ(HTNOWHERE, bubble_frame_view->NonClientHitTest(kPtOutsideBound));
- widget->CloseNow();
- RunPendingMessages();
+ TestBubbleDelegateView* bubble =
+ new TestBubbleDelegateView(anchor_widget->GetContentsView());
+ BubbleDelegateView::CreateBubble(bubble);
+ BubbleFrameView* frame = bubble->GetBubbleFrameView();
+ const int border = frame->bubble_border()->GetBorderThickness();
+
+ struct {
+ const int point;
+ const int hit;
+ } cases[] = {
+ { border, HTNOWHERE },
+ { border + 5, HTNOWHERE },
+ { border + 6, HTCLIENT },
+ { border + 50, HTCLIENT },
+ { 1000, HTNOWHERE },
+ };
+
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
+ gfx::Point point(cases[i].point, cases[i].point);
+ EXPECT_EQ(cases[i].hit, frame->NonClientHitTest(point))
+ << " with border: " << border << ", at point " << cases[i].point;
+ }
}
// Tests that the arrow is mirrored as needed to better fit the screen.
diff --git a/ui/views/views.gyp b/ui/views/views.gyp
index 64bb336..555103f 100644
--- a/ui/views/views.gyp
+++ b/ui/views/views.gyp
@@ -728,6 +728,7 @@
'view_model_utils_unittest.cc',
'view_unittest.cc',
'window/dialog_client_view_unittest.cc',
+ 'window/dialog_delegate_unittest.cc',
'widget/desktop_aura/desktop_capture_client_unittest.cc',
'widget/native_widget_aura_unittest.cc',
'widget/native_widget_unittest.cc',
diff --git a/ui/views/window/dialog_delegate_unittest.cc b/ui/views/window/dialog_delegate_unittest.cc
new file mode 100644
index 0000000..2987919
--- /dev/null
+++ b/ui/views/window/dialog_delegate_unittest.cc
@@ -0,0 +1,62 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ui/base/hit_test.h"
+#include "ui/views/bubble/bubble_border.h"
+#include "ui/views/bubble/bubble_frame_view.h"
+#include "ui/views/test/views_test_base.h"
+#include "ui/views/widget/widget.h"
+#include "ui/views/window/dialog_delegate.h"
+
+namespace views {
+
+typedef ViewsTestBase DialogTest;
+
+namespace {
+
+class TestDialog : public DialogDelegateView {
+ public:
+ TestDialog() {}
+ virtual ~TestDialog() {}
+
+ // BubbleDelegateView overrides:
+ virtual gfx::Size GetPreferredSize() OVERRIDE { return gfx::Size(200, 200); }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(TestDialog);
+};
+
+} // namespace
+
+TEST_F(DialogTest, HitTest) {
+ TestDialog* dialog = new TestDialog();
+ DialogDelegate::CreateDialogWidget(dialog, NULL, GetContext());
+ const NonClientView* view = dialog->GetWidget()->non_client_view();
+
+ if (DialogDelegate::UseNewStyle()) {
+ // Ensure that the new style's BubbleFrameView hit-tests as expected.
+ BubbleFrameView* frame = static_cast<BubbleFrameView*>(view->frame_view());
+ const int border = frame->bubble_border()->GetBorderThickness();
+
+ struct {
+ const int point;
+ const int hit;
+ } cases[] = {
+ { border, HTSYSMENU },
+ { border + 10, HTSYSMENU },
+ { border + 20, HTCAPTION },
+ { border + 40, HTCLIENT },
+ { border + 50, HTCLIENT },
+ { 1000, HTNOWHERE },
+ };
+
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
+ gfx::Point point(cases[i].point, cases[i].point);
+ EXPECT_EQ(cases[i].hit, frame->NonClientHitTest(point))
+ << " with border: " << border << ", at point " << cases[i].point;
+ }
+ }
+}
+
+} // namespace views