| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ui/base/hit_test.h" |
| 6 #include "ui/views/bubble/bubble_border.h" |
| 7 #include "ui/views/bubble/bubble_frame_view.h" |
| 8 #include "ui/views/test/views_test_base.h" |
| 9 #include "ui/views/widget/widget.h" |
| 10 #include "ui/views/window/dialog_delegate.h" |
| 11 |
| 12 namespace views { |
| 13 |
| 14 typedef ViewsTestBase DialogTest; |
| 15 |
| 16 namespace { |
| 17 |
| 18 class TestDialog : public DialogDelegateView { |
| 19 public: |
| 20 TestDialog() : can_resize_(false) {} |
| 21 virtual ~TestDialog() {} |
| 22 |
| 23 // BubbleDelegateView overrides: |
| 24 virtual gfx::Size GetPreferredSize() OVERRIDE { return gfx::Size(200, 200); } |
| 25 virtual bool CanResize() const OVERRIDE { return can_resize_; } |
| 26 |
| 27 void set_can_resize(bool can_resize) { can_resize_ = can_resize; } |
| 28 |
| 29 private: |
| 30 bool can_resize_; |
| 31 |
| 32 DISALLOW_COPY_AND_ASSIGN(TestDialog); |
| 33 }; |
| 34 |
| 35 } // namespace |
| 36 |
| 37 TEST_F(DialogTest, HitTest) { |
| 38 TestDialog* dialog = new TestDialog(); |
| 39 DialogDelegate::CreateDialogWidget(dialog, NULL, GetContext()); |
| 40 const NonClientView* view = dialog->GetWidget()->non_client_view(); |
| 41 |
| 42 if (DialogDelegate::UseNewStyle()) { |
| 43 // Ensure that the new style's BubbleFrameView hit-tests as expected. |
| 44 BubbleFrameView* frame = static_cast<BubbleFrameView*>(view->frame_view()); |
| 45 const int border = frame->bubble_border()->GetBorderThickness(); |
| 46 |
| 47 struct { |
| 48 const int point; |
| 49 const int cannot_resize_hit; |
| 50 const int can_resize_hit; |
| 51 } cases[] = { |
| 52 { border, HTSYSMENU, HTTOPLEFT }, |
| 53 { border + 3, HTSYSMENU, HTTOPLEFT }, |
| 54 { border + 4, HTSYSMENU, HTSYSMENU }, |
| 55 { border + 11, HTSYSMENU, HTSYSMENU }, |
| 56 { border + 12, HTCAPTION, HTCAPTION }, |
| 57 { border + 30, HTCAPTION, HTCAPTION }, |
| 58 { border + 40, HTCLIENT, HTCLIENT }, |
| 59 { border + 50, HTCLIENT, HTCLIENT }, |
| 60 { 1000, HTNOWHERE, HTNOWHERE }, |
| 61 }; |
| 62 |
| 63 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { |
| 64 gfx::Point point(cases[i].point, cases[i].point); |
| 65 dialog->set_can_resize(false); |
| 66 EXPECT_EQ(cases[i].cannot_resize_hit, frame->NonClientHitTest(point)) |
| 67 << " with border: " << border << ", at point " << cases[i].point; |
| 68 dialog->set_can_resize(true); |
| 69 EXPECT_EQ(cases[i].can_resize_hit, frame->NonClientHitTest(point)) |
| 70 << " with border: " << border << ", at point " << cases[i].point; |
| 71 } |
| 72 } |
| 73 } |
| 74 |
| 75 } // namespace views |
| OLD | NEW |