Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/strings/utf_string_conversions.h" | 5 #include "base/strings/utf_string_conversions.h" |
| 6 #include "ui/base/hit_test.h" | 6 #include "ui/base/hit_test.h" |
| 7 #include "ui/views/bubble/bubble_border.h" | 7 #include "ui/views/bubble/bubble_border.h" |
| 8 #include "ui/views/bubble/bubble_frame_view.h" | 8 #include "ui/views/bubble/bubble_frame_view.h" |
| 9 #include "ui/views/controls/button/checkbox.h" | 9 #include "ui/views/controls/button/checkbox.h" |
| 10 #include "ui/views/controls/button/label_button.h" | 10 #include "ui/views/controls/button/label_button.h" |
| 11 #include "ui/views/test/views_test_base.h" | 11 #include "ui/views/test/views_test_base.h" |
| 12 #include "ui/views/widget/widget.h" | 12 #include "ui/views/widget/widget.h" |
| 13 #include "ui/views/window/dialog_client_view.h" | 13 #include "ui/views/window/dialog_client_view.h" |
| 14 #include "ui/views/window/dialog_delegate.h" | 14 #include "ui/views/window/dialog_delegate.h" |
| 15 | 15 |
| 16 namespace views { | 16 namespace views { |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 class TestDialog : public DialogDelegateView, public ButtonListener { | 20 class TestDialog : public DialogDelegateView, public ButtonListener { |
| 21 public: | 21 public: |
| 22 TestDialog() | 22 TestDialog() |
| 23 : canceled_(false), | 23 : canceled_(false), |
| 24 accepted_(false), | 24 accepted_(false), |
| 25 closeable_(false), | 25 closeable_(false), |
| 26 last_pressed_button_(NULL) {} | 26 last_pressed_button_(NULL) {} |
| 27 ~TestDialog() override {} | 27 ~TestDialog() override {} |
| 28 | 28 |
| 29 // WidgetDelegate overrides: | |
| 30 bool ShouldShowWindowTitle() const override { | |
| 31 return !title_.empty(); | |
| 32 } | |
| 33 | |
| 29 // DialogDelegateView overrides: | 34 // DialogDelegateView overrides: |
| 30 bool Cancel() override { | 35 bool Cancel() override { |
| 31 canceled_ = true; | 36 canceled_ = true; |
| 32 return closeable_; | 37 return closeable_; |
| 33 } | 38 } |
| 34 bool Accept() override { | 39 bool Accept() override { |
| 35 accepted_ = true; | 40 accepted_ = true; |
| 36 return closeable_; | 41 return closeable_; |
| 37 } | 42 } |
| 38 | 43 |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 176 dialog()->GetFocusManager()->OnKeyEvent(return_key); | 181 dialog()->GetFocusManager()->OnKeyEvent(return_key); |
| 177 dialog()->CheckAndResetStates(true, false, NULL); | 182 dialog()->CheckAndResetStates(true, false, NULL); |
| 178 } | 183 } |
| 179 | 184 |
| 180 TEST_F(DialogTest, RemoveDefaultButton) { | 185 TEST_F(DialogTest, RemoveDefaultButton) { |
| 181 // Removing buttons from the dialog here should not cause a crash on close. | 186 // Removing buttons from the dialog here should not cause a crash on close. |
| 182 delete dialog()->GetDialogClientView()->ok_button(); | 187 delete dialog()->GetDialogClientView()->ok_button(); |
| 183 delete dialog()->GetDialogClientView()->cancel_button(); | 188 delete dialog()->GetDialogClientView()->cancel_button(); |
| 184 } | 189 } |
| 185 | 190 |
| 186 TEST_F(DialogTest, HitTest) { | 191 TEST_F(DialogTest, HitTest_HiddenTitle) { |
| 187 // Ensure that the new style's BubbleFrameView hit-tests as expected. | 192 // Ensure that the new style's BubbleFrameView hit-tests as expected |
|
msw
2015/02/24 22:19:46
nit: remove "the new style's" and s/when title/whe
xiaoling
2015/02/24 22:38:29
Done.
| |
| 193 // when title is hidden. | |
| 188 const NonClientView* view = dialog()->GetWidget()->non_client_view(); | 194 const NonClientView* view = dialog()->GetWidget()->non_client_view(); |
| 189 BubbleFrameView* frame = static_cast<BubbleFrameView*>(view->frame_view()); | 195 BubbleFrameView* frame = static_cast<BubbleFrameView*>(view->frame_view()); |
| 190 const int border = frame->bubble_border()->GetBorderThickness(); | 196 const int border = frame->bubble_border()->GetBorderThickness(); |
| 191 | 197 |
| 192 struct { | 198 struct { |
| 193 const int point; | 199 const int point; |
| 194 const int hit; | 200 const int hit; |
| 195 } cases[] = { | 201 } cases[] = { |
| 196 { border, HTSYSMENU }, | 202 { border, HTSYSMENU }, |
| 197 { border + 10, HTSYSMENU }, | 203 { border + 10, HTSYSMENU }, |
| 204 { border + 20, HTCLIENT }, | |
| 205 { border + 50, HTCLIENT }, | |
| 206 { border + 60, HTCLIENT }, | |
| 207 { 1000, HTNOWHERE }, | |
| 208 }; | |
| 209 | |
| 210 for (size_t i = 0; i < arraysize(cases); ++i) { | |
| 211 gfx::Point point(cases[i].point, cases[i].point); | |
| 212 EXPECT_EQ(cases[i].hit, frame->NonClientHitTest(point)) | |
| 213 << " with border: " << border << ", at point " << cases[i].point; | |
| 214 } | |
| 215 } | |
| 216 | |
| 217 TEST_F(DialogTest, HitTest_WithTitle) { | |
| 218 // Ensure that the new style's BubbleFrameView hit-tests as expected | |
|
msw
2015/02/24 22:19:46
nit: remove "the new style's" here and below; s/wh
xiaoling
2015/02/24 22:38:29
Done.
| |
| 219 // when title is present. | |
| 220 const NonClientView* view = dialog()->GetWidget()->non_client_view(); | |
| 221 dialog()->set_title(base::ASCIIToUTF16("Title")); | |
| 222 dialog()->GetWidget()->UpdateWindowTitle(); | |
| 223 BubbleFrameView* frame = static_cast<BubbleFrameView*>(view->frame_view()); | |
| 224 const int border = frame->bubble_border()->GetBorderThickness(); | |
| 225 | |
| 226 struct { | |
| 227 const int point; | |
| 228 const int hit; | |
| 229 } cases[] = { | |
| 230 { border, HTSYSMENU }, | |
| 231 { border + 10, HTSYSMENU }, | |
| 198 { border + 20, HTCAPTION }, | 232 { border + 20, HTCAPTION }, |
| 199 { border + 40, HTCLIENT }, | |
| 200 { border + 50, HTCLIENT }, | 233 { border + 50, HTCLIENT }, |
| 234 { border + 60, HTCLIENT }, | |
| 201 { 1000, HTNOWHERE }, | 235 { 1000, HTNOWHERE }, |
| 202 }; | 236 }; |
| 203 | 237 |
| 204 for (size_t i = 0; i < arraysize(cases); ++i) { | 238 for (size_t i = 0; i < arraysize(cases); ++i) { |
| 205 gfx::Point point(cases[i].point, cases[i].point); | 239 gfx::Point point(cases[i].point, cases[i].point); |
| 206 EXPECT_EQ(cases[i].hit, frame->NonClientHitTest(point)) | 240 EXPECT_EQ(cases[i].hit, frame->NonClientHitTest(point)) |
| 207 << " with border: " << border << ", at point " << cases[i].point; | 241 << " with border: " << border << ", at point " << cases[i].point; |
| 208 } | 242 } |
| 209 } | 243 } |
| 210 | 244 |
| 211 TEST_F(DialogTest, BoundsAccommodateTitle) { | 245 TEST_F(DialogTest, BoundsAccommodateTitle) { |
| 212 TestDialog* dialog2(new TestDialog()); | 246 TestDialog* dialog2(new TestDialog()); |
| 213 dialog2->set_title(base::ASCIIToUTF16("Title")); | 247 dialog2->set_title(base::ASCIIToUTF16("Title")); |
| 214 DialogDelegate::CreateDialogWidget(dialog2, GetContext(), NULL); | 248 DialogDelegate::CreateDialogWidget(dialog2, GetContext(), NULL); |
| 215 | 249 |
| 216 // Titled dialogs have taller initial frame bounds than untitled dialogs. | 250 // Titled dialogs have taller initial frame bounds than untitled dialogs. |
| 217 View* frame1 = dialog()->GetWidget()->non_client_view()->frame_view(); | 251 View* frame1 = dialog()->GetWidget()->non_client_view()->frame_view(); |
| 218 View* frame2 = dialog2->GetWidget()->non_client_view()->frame_view(); | 252 View* frame2 = dialog2->GetWidget()->non_client_view()->frame_view(); |
| 219 EXPECT_LT(frame1->GetPreferredSize().height(), | 253 EXPECT_LT(frame1->GetPreferredSize().height(), |
| 220 frame2->GetPreferredSize().height()); | 254 frame2->GetPreferredSize().height()); |
| 221 | 255 |
| 222 // Giving the default test dialog a title will yield the same bounds. | 256 // Giving the default test dialog a title will yield the same bounds. |
| 223 dialog()->set_title(base::ASCIIToUTF16("Title")); | 257 dialog()->set_title(base::ASCIIToUTF16("Title")); |
| 224 dialog()->GetWidget()->UpdateWindowTitle(); | 258 dialog()->GetWidget()->UpdateWindowTitle(); |
| 225 EXPECT_EQ(frame1->GetPreferredSize().height(), | 259 EXPECT_EQ(frame1->GetPreferredSize().height(), |
| 226 frame2->GetPreferredSize().height()); | 260 frame2->GetPreferredSize().height()); |
| 227 } | 261 } |
| 228 | 262 |
| 229 } // namespace views | 263 } // namespace views |
| OLD | NEW |