| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 <algorithm> | 5 #include <algorithm> |
| 6 #include <set> | 6 #include <set> |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 // event sequence, such as a drag. | 60 // event sequence, such as a drag. |
| 61 enum HandleMode { | 61 enum HandleMode { |
| 62 PROPAGATE_EVENTS, | 62 PROPAGATE_EVENTS, |
| 63 CONSUME_EVENTS | 63 CONSUME_EVENTS |
| 64 }; | 64 }; |
| 65 | 65 |
| 66 EventCountView() | 66 EventCountView() |
| 67 : last_flags_(0), | 67 : last_flags_(0), |
| 68 handle_mode_(PROPAGATE_EVENTS) {} | 68 handle_mode_(PROPAGATE_EVENTS) {} |
| 69 | 69 |
| 70 virtual ~EventCountView() {} | 70 ~EventCountView() override {} |
| 71 | 71 |
| 72 int GetEventCount(ui::EventType type) { | 72 int GetEventCount(ui::EventType type) { |
| 73 return event_count_[type]; | 73 return event_count_[type]; |
| 74 } | 74 } |
| 75 | 75 |
| 76 void ResetCounts() { | 76 void ResetCounts() { |
| 77 event_count_.clear(); | 77 event_count_.clear(); |
| 78 } | 78 } |
| 79 | 79 |
| 80 int last_flags() const { | 80 int last_flags() const { |
| 81 return last_flags_; | 81 return last_flags_; |
| 82 } | 82 } |
| 83 | 83 |
| 84 void set_handle_mode(HandleMode handle_mode) { | 84 void set_handle_mode(HandleMode handle_mode) { |
| 85 handle_mode_ = handle_mode; | 85 handle_mode_ = handle_mode; |
| 86 } | 86 } |
| 87 | 87 |
| 88 protected: | 88 protected: |
| 89 // Overridden from View: | 89 // Overridden from View: |
| 90 virtual void OnMouseMoved(const ui::MouseEvent& event) override { | 90 void OnMouseMoved(const ui::MouseEvent& event) override { |
| 91 // MouseMove events are not re-dispatched from the RootView. | 91 // MouseMove events are not re-dispatched from the RootView. |
| 92 ++event_count_[ui::ET_MOUSE_MOVED]; | 92 ++event_count_[ui::ET_MOUSE_MOVED]; |
| 93 last_flags_ = 0; | 93 last_flags_ = 0; |
| 94 } | 94 } |
| 95 | 95 |
| 96 // Overridden from ui::EventHandler: | 96 // Overridden from ui::EventHandler: |
| 97 virtual void OnKeyEvent(ui::KeyEvent* event) override { | 97 void OnKeyEvent(ui::KeyEvent* event) override { RecordEvent(event); } |
| 98 RecordEvent(event); | 98 void OnMouseEvent(ui::MouseEvent* event) override { RecordEvent(event); } |
| 99 } | 99 void OnScrollEvent(ui::ScrollEvent* event) override { RecordEvent(event); } |
| 100 virtual void OnMouseEvent(ui::MouseEvent* event) override { | 100 void OnGestureEvent(ui::GestureEvent* event) override { RecordEvent(event); } |
| 101 RecordEvent(event); | |
| 102 } | |
| 103 virtual void OnScrollEvent(ui::ScrollEvent* event) override { | |
| 104 RecordEvent(event); | |
| 105 } | |
| 106 virtual void OnGestureEvent(ui::GestureEvent* event) override { | |
| 107 RecordEvent(event); | |
| 108 } | |
| 109 | 101 |
| 110 private: | 102 private: |
| 111 void RecordEvent(ui::Event* event) { | 103 void RecordEvent(ui::Event* event) { |
| 112 ++event_count_[event->type()]; | 104 ++event_count_[event->type()]; |
| 113 last_flags_ = event->flags(); | 105 last_flags_ = event->flags(); |
| 114 if (handle_mode_ == CONSUME_EVENTS) | 106 if (handle_mode_ == CONSUME_EVENTS) |
| 115 event->SetHandled(); | 107 event->SetHandled(); |
| 116 } | 108 } |
| 117 | 109 |
| 118 std::map<ui::EventType, int> event_count_; | 110 std::map<ui::EventType, int> event_count_; |
| 119 int last_flags_; | 111 int last_flags_; |
| 120 HandleMode handle_mode_; | 112 HandleMode handle_mode_; |
| 121 | 113 |
| 122 DISALLOW_COPY_AND_ASSIGN(EventCountView); | 114 DISALLOW_COPY_AND_ASSIGN(EventCountView); |
| 123 }; | 115 }; |
| 124 | 116 |
| 125 // A view that keeps track of the events it receives, and consumes all scroll | 117 // A view that keeps track of the events it receives, and consumes all scroll |
| 126 // gesture events and ui::ET_SCROLL events. | 118 // gesture events and ui::ET_SCROLL events. |
| 127 class ScrollableEventCountView : public EventCountView { | 119 class ScrollableEventCountView : public EventCountView { |
| 128 public: | 120 public: |
| 129 ScrollableEventCountView() {} | 121 ScrollableEventCountView() {} |
| 130 virtual ~ScrollableEventCountView() {} | 122 ~ScrollableEventCountView() override {} |
| 131 | 123 |
| 132 private: | 124 private: |
| 133 // Overridden from ui::EventHandler: | 125 // Overridden from ui::EventHandler: |
| 134 virtual void OnGestureEvent(ui::GestureEvent* event) override { | 126 void OnGestureEvent(ui::GestureEvent* event) override { |
| 135 EventCountView::OnGestureEvent(event); | 127 EventCountView::OnGestureEvent(event); |
| 136 switch (event->type()) { | 128 switch (event->type()) { |
| 137 case ui::ET_GESTURE_SCROLL_BEGIN: | 129 case ui::ET_GESTURE_SCROLL_BEGIN: |
| 138 case ui::ET_GESTURE_SCROLL_UPDATE: | 130 case ui::ET_GESTURE_SCROLL_UPDATE: |
| 139 case ui::ET_GESTURE_SCROLL_END: | 131 case ui::ET_GESTURE_SCROLL_END: |
| 140 case ui::ET_SCROLL_FLING_START: | 132 case ui::ET_SCROLL_FLING_START: |
| 141 event->SetHandled(); | 133 event->SetHandled(); |
| 142 break; | 134 break; |
| 143 default: | 135 default: |
| 144 break; | 136 break; |
| 145 } | 137 } |
| 146 } | 138 } |
| 147 | 139 |
| 148 virtual void OnScrollEvent(ui::ScrollEvent* event) override { | 140 void OnScrollEvent(ui::ScrollEvent* event) override { |
| 149 EventCountView::OnScrollEvent(event); | 141 EventCountView::OnScrollEvent(event); |
| 150 if (event->type() == ui::ET_SCROLL) | 142 if (event->type() == ui::ET_SCROLL) |
| 151 event->SetHandled(); | 143 event->SetHandled(); |
| 152 } | 144 } |
| 153 | 145 |
| 154 DISALLOW_COPY_AND_ASSIGN(ScrollableEventCountView); | 146 DISALLOW_COPY_AND_ASSIGN(ScrollableEventCountView); |
| 155 }; | 147 }; |
| 156 | 148 |
| 157 // A view that implements GetMinimumSize. | 149 // A view that implements GetMinimumSize. |
| 158 class MinimumSizeFrameView : public NativeFrameView { | 150 class MinimumSizeFrameView : public NativeFrameView { |
| 159 public: | 151 public: |
| 160 explicit MinimumSizeFrameView(Widget* frame): NativeFrameView(frame) {} | 152 explicit MinimumSizeFrameView(Widget* frame): NativeFrameView(frame) {} |
| 161 virtual ~MinimumSizeFrameView() {} | 153 ~MinimumSizeFrameView() override {} |
| 162 | 154 |
| 163 private: | 155 private: |
| 164 // Overridden from View: | 156 // Overridden from View: |
| 165 virtual gfx::Size GetMinimumSize() const override { | 157 gfx::Size GetMinimumSize() const override { return gfx::Size(300, 400); } |
| 166 return gfx::Size(300, 400); | |
| 167 } | |
| 168 | 158 |
| 169 DISALLOW_COPY_AND_ASSIGN(MinimumSizeFrameView); | 159 DISALLOW_COPY_AND_ASSIGN(MinimumSizeFrameView); |
| 170 }; | 160 }; |
| 171 | 161 |
| 172 // An event handler that simply keeps a count of the different types of events | 162 // An event handler that simply keeps a count of the different types of events |
| 173 // it receives. | 163 // it receives. |
| 174 class EventCountHandler : public ui::EventHandler { | 164 class EventCountHandler : public ui::EventHandler { |
| 175 public: | 165 public: |
| 176 EventCountHandler() {} | 166 EventCountHandler() {} |
| 177 virtual ~EventCountHandler() {} | 167 ~EventCountHandler() override {} |
| 178 | 168 |
| 179 int GetEventCount(ui::EventType type) { | 169 int GetEventCount(ui::EventType type) { |
| 180 return event_count_[type]; | 170 return event_count_[type]; |
| 181 } | 171 } |
| 182 | 172 |
| 183 void ResetCounts() { | 173 void ResetCounts() { |
| 184 event_count_.clear(); | 174 event_count_.clear(); |
| 185 } | 175 } |
| 186 | 176 |
| 187 protected: | 177 protected: |
| 188 // Overridden from ui::EventHandler: | 178 // Overridden from ui::EventHandler: |
| 189 virtual void OnEvent(ui::Event* event) override { | 179 void OnEvent(ui::Event* event) override { |
| 190 RecordEvent(*event); | 180 RecordEvent(*event); |
| 191 ui::EventHandler::OnEvent(event); | 181 ui::EventHandler::OnEvent(event); |
| 192 } | 182 } |
| 193 | 183 |
| 194 private: | 184 private: |
| 195 void RecordEvent(const ui::Event& event) { | 185 void RecordEvent(const ui::Event& event) { |
| 196 ++event_count_[event.type()]; | 186 ++event_count_[event.type()]; |
| 197 } | 187 } |
| 198 | 188 |
| 199 std::map<ui::EventType, int> event_count_; | 189 std::map<ui::EventType, int> event_count_; |
| 200 | 190 |
| 201 DISALLOW_COPY_AND_ASSIGN(EventCountHandler); | 191 DISALLOW_COPY_AND_ASSIGN(EventCountHandler); |
| 202 }; | 192 }; |
| 203 | 193 |
| 204 // Class that closes the widget (which ends up deleting it immediately) when the | 194 // Class that closes the widget (which ends up deleting it immediately) when the |
| 205 // appropriate event is received. | 195 // appropriate event is received. |
| 206 class CloseWidgetView : public View { | 196 class CloseWidgetView : public View { |
| 207 public: | 197 public: |
| 208 explicit CloseWidgetView(ui::EventType event_type) | 198 explicit CloseWidgetView(ui::EventType event_type) |
| 209 : event_type_(event_type) { | 199 : event_type_(event_type) { |
| 210 } | 200 } |
| 211 | 201 |
| 212 // ui::EventHandler override: | 202 // ui::EventHandler override: |
| 213 virtual void OnEvent(ui::Event* event) override { | 203 void OnEvent(ui::Event* event) override { |
| 214 if (event->type() == event_type_) { | 204 if (event->type() == event_type_) { |
| 215 // Go through NativeWidgetPrivate to simulate what happens if the OS | 205 // Go through NativeWidgetPrivate to simulate what happens if the OS |
| 216 // deletes the NativeWindow out from under us. | 206 // deletes the NativeWindow out from under us. |
| 217 GetWidget()->native_widget_private()->CloseNow(); | 207 GetWidget()->native_widget_private()->CloseNow(); |
| 218 } else { | 208 } else { |
| 219 View::OnEvent(event); | 209 View::OnEvent(event); |
| 220 if (!event->IsTouchEvent()) | 210 if (!event->IsTouchEvent()) |
| 221 event->SetHandled(); | 211 event->SetHandled(); |
| 222 } | 212 } |
| 223 } | 213 } |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 //////////////////////////////////////////////////////////////////////////////// | 304 //////////////////////////////////////////////////////////////////////////////// |
| 315 // Widget ownership tests. | 305 // Widget ownership tests. |
| 316 // | 306 // |
| 317 // Tests various permutations of Widget ownership specified in the | 307 // Tests various permutations of Widget ownership specified in the |
| 318 // InitParams::Ownership param. | 308 // InitParams::Ownership param. |
| 319 | 309 |
| 320 // A WidgetTest that supplies a toplevel widget for NativeWidget to parent to. | 310 // A WidgetTest that supplies a toplevel widget for NativeWidget to parent to. |
| 321 class WidgetOwnershipTest : public WidgetTest { | 311 class WidgetOwnershipTest : public WidgetTest { |
| 322 public: | 312 public: |
| 323 WidgetOwnershipTest() {} | 313 WidgetOwnershipTest() {} |
| 324 virtual ~WidgetOwnershipTest() {} | 314 ~WidgetOwnershipTest() override {} |
| 325 | 315 |
| 326 virtual void SetUp() { | 316 void SetUp() override { |
| 327 WidgetTest::SetUp(); | 317 WidgetTest::SetUp(); |
| 328 desktop_widget_ = CreateTopLevelPlatformWidget(); | 318 desktop_widget_ = CreateTopLevelPlatformWidget(); |
| 329 } | 319 } |
| 330 | 320 |
| 331 virtual void TearDown() { | 321 void TearDown() override { |
| 332 desktop_widget_->CloseNow(); | 322 desktop_widget_->CloseNow(); |
| 333 WidgetTest::TearDown(); | 323 WidgetTest::TearDown(); |
| 334 } | 324 } |
| 335 | 325 |
| 336 private: | 326 private: |
| 337 Widget* desktop_widget_; | 327 Widget* desktop_widget_; |
| 338 | 328 |
| 339 DISALLOW_COPY_AND_ASSIGN(WidgetOwnershipTest); | 329 DISALLOW_COPY_AND_ASSIGN(WidgetOwnershipTest); |
| 340 }; | 330 }; |
| 341 | 331 |
| 342 // A bag of state to monitor destructions. | 332 // A bag of state to monitor destructions. |
| 343 struct OwnershipTestState { | 333 struct OwnershipTestState { |
| 344 OwnershipTestState() : widget_deleted(false), native_widget_deleted(false) {} | 334 OwnershipTestState() : widget_deleted(false), native_widget_deleted(false) {} |
| 345 | 335 |
| 346 bool widget_deleted; | 336 bool widget_deleted; |
| 347 bool native_widget_deleted; | 337 bool native_widget_deleted; |
| 348 }; | 338 }; |
| 349 | 339 |
| 350 // A platform NativeWidget subclass that updates a bag of state when it is | 340 // A platform NativeWidget subclass that updates a bag of state when it is |
| 351 // destroyed. | 341 // destroyed. |
| 352 class OwnershipTestNativeWidget : public PlatformNativeWidget { | 342 class OwnershipTestNativeWidget : public PlatformNativeWidget { |
| 353 public: | 343 public: |
| 354 OwnershipTestNativeWidget(internal::NativeWidgetDelegate* delegate, | 344 OwnershipTestNativeWidget(internal::NativeWidgetDelegate* delegate, |
| 355 OwnershipTestState* state) | 345 OwnershipTestState* state) |
| 356 : PlatformNativeWidget(delegate), | 346 : PlatformNativeWidget(delegate), |
| 357 state_(state) { | 347 state_(state) { |
| 358 } | 348 } |
| 359 virtual ~OwnershipTestNativeWidget() { | 349 ~OwnershipTestNativeWidget() override { |
| 360 state_->native_widget_deleted = true; | 350 state_->native_widget_deleted = true; |
| 361 } | 351 } |
| 362 | 352 |
| 363 private: | 353 private: |
| 364 OwnershipTestState* state_; | 354 OwnershipTestState* state_; |
| 365 | 355 |
| 366 DISALLOW_COPY_AND_ASSIGN(OwnershipTestNativeWidget); | 356 DISALLOW_COPY_AND_ASSIGN(OwnershipTestNativeWidget); |
| 367 }; | 357 }; |
| 368 | 358 |
| 369 // A views NativeWidget subclass that updates a bag of state when it is | 359 // A views NativeWidget subclass that updates a bag of state when it is |
| 370 // destroyed. | 360 // destroyed. |
| 371 class OwnershipTestNativeWidgetAura : public NativeWidgetCapture { | 361 class OwnershipTestNativeWidgetAura : public NativeWidgetCapture { |
| 372 public: | 362 public: |
| 373 OwnershipTestNativeWidgetAura(internal::NativeWidgetDelegate* delegate, | 363 OwnershipTestNativeWidgetAura(internal::NativeWidgetDelegate* delegate, |
| 374 OwnershipTestState* state) | 364 OwnershipTestState* state) |
| 375 : NativeWidgetCapture(delegate), | 365 : NativeWidgetCapture(delegate), |
| 376 state_(state) { | 366 state_(state) { |
| 377 } | 367 } |
| 378 virtual ~OwnershipTestNativeWidgetAura() { | 368 ~OwnershipTestNativeWidgetAura() override { |
| 379 state_->native_widget_deleted = true; | 369 state_->native_widget_deleted = true; |
| 380 } | 370 } |
| 381 | 371 |
| 382 private: | 372 private: |
| 383 OwnershipTestState* state_; | 373 OwnershipTestState* state_; |
| 384 | 374 |
| 385 DISALLOW_COPY_AND_ASSIGN(OwnershipTestNativeWidgetAura); | 375 DISALLOW_COPY_AND_ASSIGN(OwnershipTestNativeWidgetAura); |
| 386 }; | 376 }; |
| 387 | 377 |
| 388 // A Widget subclass that updates a bag of state when it is destroyed. | 378 // A Widget subclass that updates a bag of state when it is destroyed. |
| 389 class OwnershipTestWidget : public Widget { | 379 class OwnershipTestWidget : public Widget { |
| 390 public: | 380 public: |
| 391 explicit OwnershipTestWidget(OwnershipTestState* state) : state_(state) {} | 381 explicit OwnershipTestWidget(OwnershipTestState* state) : state_(state) {} |
| 392 virtual ~OwnershipTestWidget() { | 382 ~OwnershipTestWidget() override { state_->widget_deleted = true; } |
| 393 state_->widget_deleted = true; | |
| 394 } | |
| 395 | 383 |
| 396 private: | 384 private: |
| 397 OwnershipTestState* state_; | 385 OwnershipTestState* state_; |
| 398 | 386 |
| 399 DISALLOW_COPY_AND_ASSIGN(OwnershipTestWidget); | 387 DISALLOW_COPY_AND_ASSIGN(OwnershipTestWidget); |
| 400 }; | 388 }; |
| 401 | 389 |
| 402 // Widget owns its NativeWidget, part 1: NativeWidget is a platform-native | 390 // Widget owns its NativeWidget, part 1: NativeWidget is a platform-native |
| 403 // widget. | 391 // widget. |
| 404 TEST_F(WidgetOwnershipTest, Ownership_WidgetOwnsPlatformNativeWidget) { | 392 TEST_F(WidgetOwnershipTest, Ownership_WidgetOwnsPlatformNativeWidget) { |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 612 EXPECT_TRUE(state.native_widget_deleted); | 600 EXPECT_TRUE(state.native_widget_deleted); |
| 613 } | 601 } |
| 614 | 602 |
| 615 //////////////////////////////////////////////////////////////////////////////// | 603 //////////////////////////////////////////////////////////////////////////////// |
| 616 // Test to verify using various Widget methods doesn't crash when the underlying | 604 // Test to verify using various Widget methods doesn't crash when the underlying |
| 617 // NativeView is destroyed. | 605 // NativeView is destroyed. |
| 618 // | 606 // |
| 619 class WidgetWithDestroyedNativeViewTest : public ViewsTestBase { | 607 class WidgetWithDestroyedNativeViewTest : public ViewsTestBase { |
| 620 public: | 608 public: |
| 621 WidgetWithDestroyedNativeViewTest() {} | 609 WidgetWithDestroyedNativeViewTest() {} |
| 622 virtual ~WidgetWithDestroyedNativeViewTest() {} | 610 ~WidgetWithDestroyedNativeViewTest() override {} |
| 623 | 611 |
| 624 void InvokeWidgetMethods(Widget* widget) { | 612 void InvokeWidgetMethods(Widget* widget) { |
| 625 widget->GetNativeView(); | 613 widget->GetNativeView(); |
| 626 widget->GetNativeWindow(); | 614 widget->GetNativeWindow(); |
| 627 ui::Accelerator accelerator; | 615 ui::Accelerator accelerator; |
| 628 widget->GetAccelerator(0, &accelerator); | 616 widget->GetAccelerator(0, &accelerator); |
| 629 widget->GetTopLevelWidget(); | 617 widget->GetTopLevelWidget(); |
| 630 widget->GetWindowBoundsInScreen(); | 618 widget->GetWindowBoundsInScreen(); |
| 631 widget->GetClientAreaBoundsInScreen(); | 619 widget->GetClientAreaBoundsInScreen(); |
| 632 widget->SetBounds(gfx::Rect(0, 0, 100, 80)); | 620 widget->SetBounds(gfx::Rect(0, 0, 100, 80)); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 708 public: | 696 public: |
| 709 WidgetObserverTest() | 697 WidgetObserverTest() |
| 710 : active_(NULL), | 698 : active_(NULL), |
| 711 widget_closed_(NULL), | 699 widget_closed_(NULL), |
| 712 widget_activated_(NULL), | 700 widget_activated_(NULL), |
| 713 widget_shown_(NULL), | 701 widget_shown_(NULL), |
| 714 widget_hidden_(NULL), | 702 widget_hidden_(NULL), |
| 715 widget_bounds_changed_(NULL) { | 703 widget_bounds_changed_(NULL) { |
| 716 } | 704 } |
| 717 | 705 |
| 718 virtual ~WidgetObserverTest() {} | 706 ~WidgetObserverTest() override {} |
| 719 | 707 |
| 720 // Overridden from WidgetObserver: | 708 // Overridden from WidgetObserver: |
| 721 virtual void OnWidgetDestroying(Widget* widget) override { | 709 void OnWidgetDestroying(Widget* widget) override { |
| 722 if (active_ == widget) | 710 if (active_ == widget) |
| 723 active_ = NULL; | 711 active_ = NULL; |
| 724 widget_closed_ = widget; | 712 widget_closed_ = widget; |
| 725 } | 713 } |
| 726 | 714 |
| 727 virtual void OnWidgetActivationChanged(Widget* widget, | 715 void OnWidgetActivationChanged(Widget* widget, bool active) override { |
| 728 bool active) override { | |
| 729 if (active) { | 716 if (active) { |
| 730 if (widget_activated_) | 717 if (widget_activated_) |
| 731 widget_activated_->Deactivate(); | 718 widget_activated_->Deactivate(); |
| 732 widget_activated_ = widget; | 719 widget_activated_ = widget; |
| 733 active_ = widget; | 720 active_ = widget; |
| 734 } else { | 721 } else { |
| 735 if (widget_activated_ == widget) | 722 if (widget_activated_ == widget) |
| 736 widget_activated_ = NULL; | 723 widget_activated_ = NULL; |
| 737 widget_deactivated_ = widget; | 724 widget_deactivated_ = widget; |
| 738 } | 725 } |
| 739 } | 726 } |
| 740 | 727 |
| 741 virtual void OnWidgetVisibilityChanged(Widget* widget, | 728 void OnWidgetVisibilityChanged(Widget* widget, bool visible) override { |
| 742 bool visible) override { | |
| 743 if (visible) | 729 if (visible) |
| 744 widget_shown_ = widget; | 730 widget_shown_ = widget; |
| 745 else | 731 else |
| 746 widget_hidden_ = widget; | 732 widget_hidden_ = widget; |
| 747 } | 733 } |
| 748 | 734 |
| 749 virtual void OnWidgetBoundsChanged(Widget* widget, | 735 void OnWidgetBoundsChanged(Widget* widget, |
| 750 const gfx::Rect& new_bounds) override { | 736 const gfx::Rect& new_bounds) override { |
| 751 widget_bounds_changed_ = widget; | 737 widget_bounds_changed_ = widget; |
| 752 } | 738 } |
| 753 | 739 |
| 754 void reset() { | 740 void reset() { |
| 755 active_ = NULL; | 741 active_ = NULL; |
| 756 widget_closed_ = NULL; | 742 widget_closed_ = NULL; |
| 757 widget_activated_ = NULL; | 743 widget_activated_ = NULL; |
| 758 widget_deactivated_ = NULL; | 744 widget_deactivated_ = NULL; |
| 759 widget_shown_ = NULL; | 745 widget_shown_ = NULL; |
| 760 widget_hidden_ = NULL; | 746 widget_hidden_ = NULL; |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1065 | 1051 |
| 1066 // Closing the bubble should result in focus going back to the contents view. | 1052 // Closing the bubble should result in focus going back to the contents view. |
| 1067 EXPECT_TRUE(contents_view->HasFocus()); | 1053 EXPECT_TRUE(contents_view->HasFocus()); |
| 1068 } | 1054 } |
| 1069 | 1055 |
| 1070 class TestBubbleDelegateView : public BubbleDelegateView { | 1056 class TestBubbleDelegateView : public BubbleDelegateView { |
| 1071 public: | 1057 public: |
| 1072 TestBubbleDelegateView(View* anchor) | 1058 TestBubbleDelegateView(View* anchor) |
| 1073 : BubbleDelegateView(anchor, BubbleBorder::NONE), | 1059 : BubbleDelegateView(anchor, BubbleBorder::NONE), |
| 1074 reset_controls_called_(false) {} | 1060 reset_controls_called_(false) {} |
| 1075 virtual ~TestBubbleDelegateView() {} | 1061 ~TestBubbleDelegateView() override {} |
| 1076 | 1062 |
| 1077 virtual bool ShouldShowCloseButton() const override { | 1063 bool ShouldShowCloseButton() const override { |
| 1078 reset_controls_called_ = true; | 1064 reset_controls_called_ = true; |
| 1079 return true; | 1065 return true; |
| 1080 } | 1066 } |
| 1081 | 1067 |
| 1082 mutable bool reset_controls_called_; | 1068 mutable bool reset_controls_called_; |
| 1083 }; | 1069 }; |
| 1084 | 1070 |
| 1085 TEST_F(WidgetTest, BubbleControlsResetOnInit) { | 1071 TEST_F(WidgetTest, BubbleControlsResetOnInit) { |
| 1086 Widget* anchor = CreateTopLevelPlatformWidget(); | 1072 Widget* anchor = CreateTopLevelPlatformWidget(); |
| 1087 anchor->Show(); | 1073 anchor->Show(); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1122 // This class validates whether paints are received for a visible Widget. | 1108 // This class validates whether paints are received for a visible Widget. |
| 1123 // To achieve this it overrides the Show and Close methods on the Widget class | 1109 // To achieve this it overrides the Show and Close methods on the Widget class |
| 1124 // and sets state whether subsequent paints are expected. | 1110 // and sets state whether subsequent paints are expected. |
| 1125 class DesktopAuraTestValidPaintWidget : public views::Widget { | 1111 class DesktopAuraTestValidPaintWidget : public views::Widget { |
| 1126 public: | 1112 public: |
| 1127 DesktopAuraTestValidPaintWidget() | 1113 DesktopAuraTestValidPaintWidget() |
| 1128 : received_paint_(false), | 1114 : received_paint_(false), |
| 1129 expect_paint_(true), | 1115 expect_paint_(true), |
| 1130 received_paint_while_hidden_(false) {} | 1116 received_paint_while_hidden_(false) {} |
| 1131 | 1117 |
| 1132 virtual ~DesktopAuraTestValidPaintWidget() {} | 1118 ~DesktopAuraTestValidPaintWidget() override {} |
| 1133 | 1119 |
| 1134 void InitForTest(Widget::InitParams create_params); | 1120 void InitForTest(Widget::InitParams create_params); |
| 1135 | 1121 |
| 1136 virtual void Show() override { | 1122 void Show() override { |
| 1137 expect_paint_ = true; | 1123 expect_paint_ = true; |
| 1138 views::Widget::Show(); | 1124 views::Widget::Show(); |
| 1139 } | 1125 } |
| 1140 | 1126 |
| 1141 virtual void Close() override { | 1127 void Close() override { |
| 1142 expect_paint_ = false; | 1128 expect_paint_ = false; |
| 1143 views::Widget::Close(); | 1129 views::Widget::Close(); |
| 1144 } | 1130 } |
| 1145 | 1131 |
| 1146 void Hide() { | 1132 void Hide() { |
| 1147 expect_paint_ = false; | 1133 expect_paint_ = false; |
| 1148 views::Widget::Hide(); | 1134 views::Widget::Hide(); |
| 1149 } | 1135 } |
| 1150 | 1136 |
| 1151 virtual void OnNativeWidgetPaint(gfx::Canvas* canvas) override { | 1137 void OnNativeWidgetPaint(gfx::Canvas* canvas) override { |
| 1152 received_paint_ = true; | 1138 received_paint_ = true; |
| 1153 EXPECT_TRUE(expect_paint_); | 1139 EXPECT_TRUE(expect_paint_); |
| 1154 if (!expect_paint_) | 1140 if (!expect_paint_) |
| 1155 received_paint_while_hidden_ = true; | 1141 received_paint_while_hidden_ = true; |
| 1156 views::Widget::OnNativeWidgetPaint(canvas); | 1142 views::Widget::OnNativeWidgetPaint(canvas); |
| 1157 } | 1143 } |
| 1158 | 1144 |
| 1159 bool ReadReceivedPaintAndReset() { | 1145 bool ReadReceivedPaintAndReset() { |
| 1160 bool result = received_paint_; | 1146 bool result = received_paint_; |
| 1161 received_paint_ = false; | 1147 received_paint_ = false; |
| (...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1562 } | 1548 } |
| 1563 | 1549 |
| 1564 namespace { | 1550 namespace { |
| 1565 | 1551 |
| 1566 // ui::EventHandler which handles all mouse press events. | 1552 // ui::EventHandler which handles all mouse press events. |
| 1567 class MousePressEventConsumer : public ui::EventHandler { | 1553 class MousePressEventConsumer : public ui::EventHandler { |
| 1568 public: | 1554 public: |
| 1569 explicit MousePressEventConsumer() { | 1555 explicit MousePressEventConsumer() { |
| 1570 } | 1556 } |
| 1571 | 1557 |
| 1572 virtual ~MousePressEventConsumer() { | 1558 ~MousePressEventConsumer() override {} |
| 1573 } | |
| 1574 | 1559 |
| 1575 private: | 1560 private: |
| 1576 // ui::EventHandler: | 1561 // ui::EventHandler: |
| 1577 virtual void OnMouseEvent(ui::MouseEvent* event) override { | 1562 void OnMouseEvent(ui::MouseEvent* event) override { |
| 1578 if (event->type() == ui::ET_MOUSE_PRESSED) | 1563 if (event->type() == ui::ET_MOUSE_PRESSED) |
| 1579 event->SetHandled(); | 1564 event->SetHandled(); |
| 1580 } | 1565 } |
| 1581 | 1566 |
| 1582 DISALLOW_COPY_AND_ASSIGN(MousePressEventConsumer); | 1567 DISALLOW_COPY_AND_ASSIGN(MousePressEventConsumer); |
| 1583 }; | 1568 }; |
| 1584 | 1569 |
| 1585 } // namespace | 1570 } // namespace |
| 1586 | 1571 |
| 1587 // Test that mouse presses and mouse releases are dispatched normally when a | 1572 // Test that mouse presses and mouse releases are dispatched normally when a |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1612 // been invoked. | 1597 // been invoked. |
| 1613 class ClosingDelegate : public WidgetDelegate { | 1598 class ClosingDelegate : public WidgetDelegate { |
| 1614 public: | 1599 public: |
| 1615 ClosingDelegate() : count_(0), widget_(NULL) {} | 1600 ClosingDelegate() : count_(0), widget_(NULL) {} |
| 1616 | 1601 |
| 1617 int count() const { return count_; } | 1602 int count() const { return count_; } |
| 1618 | 1603 |
| 1619 void set_widget(views::Widget* widget) { widget_ = widget; } | 1604 void set_widget(views::Widget* widget) { widget_ = widget; } |
| 1620 | 1605 |
| 1621 // WidgetDelegate overrides: | 1606 // WidgetDelegate overrides: |
| 1622 virtual Widget* GetWidget() override { return widget_; } | 1607 Widget* GetWidget() override { return widget_; } |
| 1623 virtual const Widget* GetWidget() const override { return widget_; } | 1608 const Widget* GetWidget() const override { return widget_; } |
| 1624 virtual void WindowClosing() override { | 1609 void WindowClosing() override { count_++; } |
| 1625 count_++; | |
| 1626 } | |
| 1627 | 1610 |
| 1628 private: | 1611 private: |
| 1629 int count_; | 1612 int count_; |
| 1630 views::Widget* widget_; | 1613 views::Widget* widget_; |
| 1631 | 1614 |
| 1632 DISALLOW_COPY_AND_ASSIGN(ClosingDelegate); | 1615 DISALLOW_COPY_AND_ASSIGN(ClosingDelegate); |
| 1633 }; | 1616 }; |
| 1634 | 1617 |
| 1635 // Verifies WindowClosing() is invoked correctly on the delegate when a Widget | 1618 // Verifies WindowClosing() is invoked correctly on the delegate when a Widget |
| 1636 // is closed. | 1619 // is closed. |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1744 generator.GestureTapAt(widget->GetWindowBoundsInScreen().CenterPoint()); | 1727 generator.GestureTapAt(widget->GetWindowBoundsInScreen().CenterPoint()); |
| 1745 EXPECT_FALSE(deletion_observer.IsWidgetAlive()); | 1728 EXPECT_FALSE(deletion_observer.IsWidgetAlive()); |
| 1746 | 1729 |
| 1747 // Yay we did not crash! | 1730 // Yay we did not crash! |
| 1748 } | 1731 } |
| 1749 | 1732 |
| 1750 // See description of RunGetNativeThemeFromDestructor() for details. | 1733 // See description of RunGetNativeThemeFromDestructor() for details. |
| 1751 class GetNativeThemeFromDestructorView : public WidgetDelegateView { | 1734 class GetNativeThemeFromDestructorView : public WidgetDelegateView { |
| 1752 public: | 1735 public: |
| 1753 GetNativeThemeFromDestructorView() {} | 1736 GetNativeThemeFromDestructorView() {} |
| 1754 virtual ~GetNativeThemeFromDestructorView() { | 1737 ~GetNativeThemeFromDestructorView() override { VerifyNativeTheme(); } |
| 1755 VerifyNativeTheme(); | |
| 1756 } | |
| 1757 | 1738 |
| 1758 virtual View* GetContentsView() override { | 1739 View* GetContentsView() override { return this; } |
| 1759 return this; | |
| 1760 } | |
| 1761 | 1740 |
| 1762 private: | 1741 private: |
| 1763 void VerifyNativeTheme() { | 1742 void VerifyNativeTheme() { |
| 1764 ASSERT_TRUE(GetNativeTheme() != NULL); | 1743 ASSERT_TRUE(GetNativeTheme() != NULL); |
| 1765 } | 1744 } |
| 1766 | 1745 |
| 1767 DISALLOW_COPY_AND_ASSIGN(GetNativeThemeFromDestructorView); | 1746 DISALLOW_COPY_AND_ASSIGN(GetNativeThemeFromDestructorView); |
| 1768 }; | 1747 }; |
| 1769 | 1748 |
| 1770 // Verifies GetNativeTheme() from the destructor of a WidgetDelegateView doesn't | 1749 // Verifies GetNativeTheme() from the destructor of a WidgetDelegateView doesn't |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1798 } | 1777 } |
| 1799 | 1778 |
| 1800 // Used by HideCloseDestroy. Allows setting a boolean when the widget is | 1779 // Used by HideCloseDestroy. Allows setting a boolean when the widget is |
| 1801 // destroyed. | 1780 // destroyed. |
| 1802 class CloseDestroysWidget : public Widget { | 1781 class CloseDestroysWidget : public Widget { |
| 1803 public: | 1782 public: |
| 1804 explicit CloseDestroysWidget(bool* destroyed) | 1783 explicit CloseDestroysWidget(bool* destroyed) |
| 1805 : destroyed_(destroyed) { | 1784 : destroyed_(destroyed) { |
| 1806 } | 1785 } |
| 1807 | 1786 |
| 1808 virtual ~CloseDestroysWidget() { | 1787 ~CloseDestroysWidget() override { |
| 1809 if (destroyed_) { | 1788 if (destroyed_) { |
| 1810 *destroyed_ = true; | 1789 *destroyed_ = true; |
| 1811 base::MessageLoop::current()->QuitNow(); | 1790 base::MessageLoop::current()->QuitNow(); |
| 1812 } | 1791 } |
| 1813 } | 1792 } |
| 1814 | 1793 |
| 1815 void Detach() { destroyed_ = NULL; } | 1794 void Detach() { destroyed_ = NULL; } |
| 1816 | 1795 |
| 1817 private: | 1796 private: |
| 1818 // If non-null set to true from destructor. | 1797 // If non-null set to true from destructor. |
| 1819 bool* destroyed_; | 1798 bool* destroyed_; |
| 1820 | 1799 |
| 1821 DISALLOW_COPY_AND_ASSIGN(CloseDestroysWidget); | 1800 DISALLOW_COPY_AND_ASSIGN(CloseDestroysWidget); |
| 1822 }; | 1801 }; |
| 1823 | 1802 |
| 1824 // An observer that registers that an animation has ended. | 1803 // An observer that registers that an animation has ended. |
| 1825 class AnimationEndObserver : public ui::ImplicitAnimationObserver { | 1804 class AnimationEndObserver : public ui::ImplicitAnimationObserver { |
| 1826 public: | 1805 public: |
| 1827 AnimationEndObserver() : animation_completed_(false) {} | 1806 AnimationEndObserver() : animation_completed_(false) {} |
| 1828 virtual ~AnimationEndObserver() {} | 1807 ~AnimationEndObserver() override {} |
| 1829 | 1808 |
| 1830 bool animation_completed() const { return animation_completed_; } | 1809 bool animation_completed() const { return animation_completed_; } |
| 1831 | 1810 |
| 1832 // ui::ImplicitAnimationObserver: | 1811 // ui::ImplicitAnimationObserver: |
| 1833 virtual void OnImplicitAnimationsCompleted() override { | 1812 void OnImplicitAnimationsCompleted() override { animation_completed_ = true; } |
| 1834 animation_completed_ = true; | |
| 1835 } | |
| 1836 | 1813 |
| 1837 private: | 1814 private: |
| 1838 bool animation_completed_; | 1815 bool animation_completed_; |
| 1839 | 1816 |
| 1840 DISALLOW_COPY_AND_ASSIGN(AnimationEndObserver); | 1817 DISALLOW_COPY_AND_ASSIGN(AnimationEndObserver); |
| 1841 }; | 1818 }; |
| 1842 | 1819 |
| 1843 // An observer that registers the bounds of a widget on destruction. | 1820 // An observer that registers the bounds of a widget on destruction. |
| 1844 class WidgetBoundsObserver : public WidgetObserver { | 1821 class WidgetBoundsObserver : public WidgetObserver { |
| 1845 public: | 1822 public: |
| 1846 WidgetBoundsObserver() {} | 1823 WidgetBoundsObserver() {} |
| 1847 virtual ~WidgetBoundsObserver() {} | 1824 ~WidgetBoundsObserver() override {} |
| 1848 | 1825 |
| 1849 gfx::Rect bounds() { return bounds_; } | 1826 gfx::Rect bounds() { return bounds_; } |
| 1850 | 1827 |
| 1851 // WidgetObserver: | 1828 // WidgetObserver: |
| 1852 virtual void OnWidgetDestroying(Widget* widget) override { | 1829 void OnWidgetDestroying(Widget* widget) override { |
| 1853 bounds_ = widget->GetWindowBoundsInScreen(); | 1830 bounds_ = widget->GetWindowBoundsInScreen(); |
| 1854 } | 1831 } |
| 1855 | 1832 |
| 1856 private: | 1833 private: |
| 1857 gfx::Rect bounds_; | 1834 gfx::Rect bounds_; |
| 1858 | 1835 |
| 1859 DISALLOW_COPY_AND_ASSIGN(WidgetBoundsObserver); | 1836 DISALLOW_COPY_AND_ASSIGN(WidgetBoundsObserver); |
| 1860 }; | 1837 }; |
| 1861 | 1838 |
| 1862 // Verifies Close() results in destroying. | 1839 // Verifies Close() results in destroying. |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1913 EXPECT_TRUE(animation_observer.animation_completed()); | 1890 EXPECT_TRUE(animation_observer.animation_completed()); |
| 1914 EXPECT_EQ(widget_observer.bounds(), bounds); | 1891 EXPECT_EQ(widget_observer.bounds(), bounds); |
| 1915 } | 1892 } |
| 1916 | 1893 |
| 1917 // A view that consumes mouse-pressed event and gesture-tap-down events. | 1894 // A view that consumes mouse-pressed event and gesture-tap-down events. |
| 1918 class RootViewTestView : public View { | 1895 class RootViewTestView : public View { |
| 1919 public: | 1896 public: |
| 1920 RootViewTestView(): View() {} | 1897 RootViewTestView(): View() {} |
| 1921 | 1898 |
| 1922 private: | 1899 private: |
| 1923 virtual bool OnMousePressed(const ui::MouseEvent& event) override { | 1900 bool OnMousePressed(const ui::MouseEvent& event) override { return true; } |
| 1924 return true; | |
| 1925 } | |
| 1926 | 1901 |
| 1927 virtual void OnGestureEvent(ui::GestureEvent* event) override { | 1902 void OnGestureEvent(ui::GestureEvent* event) override { |
| 1928 if (event->type() == ui::ET_GESTURE_TAP_DOWN) | 1903 if (event->type() == ui::ET_GESTURE_TAP_DOWN) |
| 1929 event->SetHandled(); | 1904 event->SetHandled(); |
| 1930 } | 1905 } |
| 1931 }; | 1906 }; |
| 1932 | 1907 |
| 1933 // Checks if RootView::*_handler_ fields are unset when widget is hidden. | 1908 // Checks if RootView::*_handler_ fields are unset when widget is hidden. |
| 1934 // Fails on chromium.webkit Windows bot, see crbug.com/264872. | 1909 // Fails on chromium.webkit Windows bot, see crbug.com/264872. |
| 1935 #if defined(OS_WIN) | 1910 #if defined(OS_WIN) |
| 1936 #define MAYBE_DisableTestRootViewHandlersWhenHidden\ | 1911 #define MAYBE_DisableTestRootViewHandlersWhenHidden\ |
| 1937 DISABLED_TestRootViewHandlersWhenHidden | 1912 DISABLED_TestRootViewHandlersWhenHidden |
| (...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2456 widget->Close(); | 2431 widget->Close(); |
| 2457 } | 2432 } |
| 2458 | 2433 |
| 2459 // A class used in WidgetTest.GestureEventLocationWhileBubbling to verify | 2434 // A class used in WidgetTest.GestureEventLocationWhileBubbling to verify |
| 2460 // that when a gesture event bubbles up a View hierarchy, the location | 2435 // that when a gesture event bubbles up a View hierarchy, the location |
| 2461 // of a gesture event seen by each View is in the local coordinate space | 2436 // of a gesture event seen by each View is in the local coordinate space |
| 2462 // of that View. | 2437 // of that View. |
| 2463 class GestureLocationView : public EventCountView { | 2438 class GestureLocationView : public EventCountView { |
| 2464 public: | 2439 public: |
| 2465 GestureLocationView() {} | 2440 GestureLocationView() {} |
| 2466 virtual ~GestureLocationView() {} | 2441 ~GestureLocationView() override {} |
| 2467 | 2442 |
| 2468 void set_expected_location(gfx::Point expected_location) { | 2443 void set_expected_location(gfx::Point expected_location) { |
| 2469 expected_location_ = expected_location; | 2444 expected_location_ = expected_location; |
| 2470 } | 2445 } |
| 2471 | 2446 |
| 2472 // EventCountView: | 2447 // EventCountView: |
| 2473 virtual void OnGestureEvent(ui::GestureEvent* event) override { | 2448 void OnGestureEvent(ui::GestureEvent* event) override { |
| 2474 EventCountView::OnGestureEvent(event); | 2449 EventCountView::OnGestureEvent(event); |
| 2475 | 2450 |
| 2476 // Verify that the location of |event| is in the local coordinate | 2451 // Verify that the location of |event| is in the local coordinate |
| 2477 // space of |this|. | 2452 // space of |this|. |
| 2478 EXPECT_EQ(expected_location_, event->location()); | 2453 EXPECT_EQ(expected_location_, event->location()); |
| 2479 } | 2454 } |
| 2480 | 2455 |
| 2481 private: | 2456 private: |
| 2482 // The expected location of a gesture event dispatched to |this|. | 2457 // The expected location of a gesture event dispatched to |this|. |
| 2483 gfx::Point expected_location_; | 2458 gfx::Point expected_location_; |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2701 // Used by DestroyChildWidgetsInOrder. On destruction adds the supplied name to | 2676 // Used by DestroyChildWidgetsInOrder. On destruction adds the supplied name to |
| 2702 // a vector. | 2677 // a vector. |
| 2703 class DestroyedTrackingView : public View { | 2678 class DestroyedTrackingView : public View { |
| 2704 public: | 2679 public: |
| 2705 DestroyedTrackingView(const std::string& name, | 2680 DestroyedTrackingView(const std::string& name, |
| 2706 std::vector<std::string>* add_to) | 2681 std::vector<std::string>* add_to) |
| 2707 : name_(name), | 2682 : name_(name), |
| 2708 add_to_(add_to) { | 2683 add_to_(add_to) { |
| 2709 } | 2684 } |
| 2710 | 2685 |
| 2711 virtual ~DestroyedTrackingView() { | 2686 ~DestroyedTrackingView() override { add_to_->push_back(name_); } |
| 2712 add_to_->push_back(name_); | |
| 2713 } | |
| 2714 | 2687 |
| 2715 private: | 2688 private: |
| 2716 const std::string name_; | 2689 const std::string name_; |
| 2717 std::vector<std::string>* add_to_; | 2690 std::vector<std::string>* add_to_; |
| 2718 | 2691 |
| 2719 DISALLOW_COPY_AND_ASSIGN(DestroyedTrackingView); | 2692 DISALLOW_COPY_AND_ASSIGN(DestroyedTrackingView); |
| 2720 }; | 2693 }; |
| 2721 | 2694 |
| 2722 class WidgetChildDestructionTest : public WidgetTest { | 2695 class WidgetChildDestructionTest : public WidgetTest { |
| 2723 public: | 2696 public: |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2787 // See description of RunDestroyChildWidgetsTest(). | 2760 // See description of RunDestroyChildWidgetsTest(). |
| 2788 TEST_F(WidgetChildDestructionTest, DestroyChildWidgetsInOrder) { | 2761 TEST_F(WidgetChildDestructionTest, DestroyChildWidgetsInOrder) { |
| 2789 RunDestroyChildWidgetsTest(false, false); | 2762 RunDestroyChildWidgetsTest(false, false); |
| 2790 } | 2763 } |
| 2791 | 2764 |
| 2792 #if !defined(OS_CHROMEOS) | 2765 #if !defined(OS_CHROMEOS) |
| 2793 // Provides functionality to create a window modal dialog. | 2766 // Provides functionality to create a window modal dialog. |
| 2794 class ModalDialogDelegate : public DialogDelegateView { | 2767 class ModalDialogDelegate : public DialogDelegateView { |
| 2795 public: | 2768 public: |
| 2796 ModalDialogDelegate() {} | 2769 ModalDialogDelegate() {} |
| 2797 virtual ~ModalDialogDelegate() {} | 2770 ~ModalDialogDelegate() override {} |
| 2798 | 2771 |
| 2799 // WidgetDelegate overrides. | 2772 // WidgetDelegate overrides. |
| 2800 virtual ui::ModalType GetModalType() const override { | 2773 ui::ModalType GetModalType() const override { return ui::MODAL_TYPE_WINDOW; } |
| 2801 return ui::MODAL_TYPE_WINDOW; | |
| 2802 } | |
| 2803 | 2774 |
| 2804 private: | 2775 private: |
| 2805 DISALLOW_COPY_AND_ASSIGN(ModalDialogDelegate); | 2776 DISALLOW_COPY_AND_ASSIGN(ModalDialogDelegate); |
| 2806 }; | 2777 }; |
| 2807 | 2778 |
| 2808 // This test verifies that whether mouse events when a modal dialog is | 2779 // This test verifies that whether mouse events when a modal dialog is |
| 2809 // displayed are eaten or recieved by the dialog. | 2780 // displayed are eaten or recieved by the dialog. |
| 2810 TEST_F(WidgetTest, WindowMouseModalityTest) { | 2781 TEST_F(WidgetTest, WindowMouseModalityTest) { |
| 2811 // Create a top level widget. | 2782 // Create a top level widget. |
| 2812 Widget top_level_widget; | 2783 Widget top_level_widget; |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3099 widget2.CloseNow(); | 3070 widget2.CloseNow(); |
| 3100 } | 3071 } |
| 3101 #endif // !defined(OS_CHROMEOS) | 3072 #endif // !defined(OS_CHROMEOS) |
| 3102 | 3073 |
| 3103 namespace { | 3074 namespace { |
| 3104 | 3075 |
| 3105 class FullscreenAwareFrame : public views::NonClientFrameView { | 3076 class FullscreenAwareFrame : public views::NonClientFrameView { |
| 3106 public: | 3077 public: |
| 3107 explicit FullscreenAwareFrame(views::Widget* widget) | 3078 explicit FullscreenAwareFrame(views::Widget* widget) |
| 3108 : widget_(widget), fullscreen_layout_called_(false) {} | 3079 : widget_(widget), fullscreen_layout_called_(false) {} |
| 3109 virtual ~FullscreenAwareFrame() {} | 3080 ~FullscreenAwareFrame() override {} |
| 3110 | 3081 |
| 3111 // views::NonClientFrameView overrides: | 3082 // views::NonClientFrameView overrides: |
| 3112 virtual gfx::Rect GetBoundsForClientView() const override { | 3083 gfx::Rect GetBoundsForClientView() const override { return gfx::Rect(); } |
| 3113 return gfx::Rect(); | 3084 gfx::Rect GetWindowBoundsForClientBounds( |
| 3114 } | |
| 3115 virtual gfx::Rect GetWindowBoundsForClientBounds( | |
| 3116 const gfx::Rect& client_bounds) const override { | 3085 const gfx::Rect& client_bounds) const override { |
| 3117 return gfx::Rect(); | 3086 return gfx::Rect(); |
| 3118 } | 3087 } |
| 3119 virtual int NonClientHitTest(const gfx::Point& point) override { | 3088 int NonClientHitTest(const gfx::Point& point) override { return HTNOWHERE; } |
| 3120 return HTNOWHERE; | 3089 void GetWindowMask(const gfx::Size& size, gfx::Path* window_mask) override {} |
| 3121 } | 3090 void ResetWindowControls() override {} |
| 3122 virtual void GetWindowMask(const gfx::Size& size, | 3091 void UpdateWindowIcon() override {} |
| 3123 gfx::Path* window_mask) override {} | 3092 void UpdateWindowTitle() override {} |
| 3124 virtual void ResetWindowControls() override {} | 3093 void SizeConstraintsChanged() override {} |
| 3125 virtual void UpdateWindowIcon() override {} | |
| 3126 virtual void UpdateWindowTitle() override {} | |
| 3127 virtual void SizeConstraintsChanged() override {} | |
| 3128 | 3094 |
| 3129 // views::View overrides: | 3095 // views::View overrides: |
| 3130 virtual void Layout() override { | 3096 void Layout() override { |
| 3131 if (widget_->IsFullscreen()) | 3097 if (widget_->IsFullscreen()) |
| 3132 fullscreen_layout_called_ = true; | 3098 fullscreen_layout_called_ = true; |
| 3133 } | 3099 } |
| 3134 | 3100 |
| 3135 bool fullscreen_layout_called() const { return fullscreen_layout_called_; } | 3101 bool fullscreen_layout_called() const { return fullscreen_layout_called_; } |
| 3136 | 3102 |
| 3137 private: | 3103 private: |
| 3138 views::Widget* widget_; | 3104 views::Widget* widget_; |
| 3139 bool fullscreen_layout_called_; | 3105 bool fullscreen_layout_called_; |
| 3140 | 3106 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 3163 } | 3129 } |
| 3164 | 3130 |
| 3165 #if !defined(OS_CHROMEOS) | 3131 #if !defined(OS_CHROMEOS) |
| 3166 namespace { | 3132 namespace { |
| 3167 | 3133 |
| 3168 // Trivial WidgetObserverTest that invokes Widget::IsActive() from | 3134 // Trivial WidgetObserverTest that invokes Widget::IsActive() from |
| 3169 // OnWindowDestroying. | 3135 // OnWindowDestroying. |
| 3170 class IsActiveFromDestroyObserver : public WidgetObserver { | 3136 class IsActiveFromDestroyObserver : public WidgetObserver { |
| 3171 public: | 3137 public: |
| 3172 IsActiveFromDestroyObserver() {} | 3138 IsActiveFromDestroyObserver() {} |
| 3173 virtual ~IsActiveFromDestroyObserver() {} | 3139 ~IsActiveFromDestroyObserver() override {} |
| 3174 virtual void OnWidgetDestroying(Widget* widget) override { | 3140 void OnWidgetDestroying(Widget* widget) override { widget->IsActive(); } |
| 3175 widget->IsActive(); | |
| 3176 } | |
| 3177 | 3141 |
| 3178 private: | 3142 private: |
| 3179 DISALLOW_COPY_AND_ASSIGN(IsActiveFromDestroyObserver); | 3143 DISALLOW_COPY_AND_ASSIGN(IsActiveFromDestroyObserver); |
| 3180 }; | 3144 }; |
| 3181 | 3145 |
| 3182 } // namespace | 3146 } // namespace |
| 3183 | 3147 |
| 3184 // Verifies Widget::IsActive() invoked from | 3148 // Verifies Widget::IsActive() invoked from |
| 3185 // WidgetObserver::OnWidgetDestroying() in a child widget doesn't crash. | 3149 // WidgetObserver::OnWidgetDestroying() in a child widget doesn't crash. |
| 3186 TEST_F(WidgetTest, IsActiveFromDestroy) { | 3150 TEST_F(WidgetTest, IsActiveFromDestroy) { |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3370 | 3334 |
| 3371 EXPECT_EQ(test_rect, root_view->bounds()); | 3335 EXPECT_EQ(test_rect, root_view->bounds()); |
| 3372 widget->ReorderNativeViews(); | 3336 widget->ReorderNativeViews(); |
| 3373 EXPECT_EQ(test_rect, root_view->bounds()); | 3337 EXPECT_EQ(test_rect, root_view->bounds()); |
| 3374 | 3338 |
| 3375 widget->CloseNow(); | 3339 widget->CloseNow(); |
| 3376 } | 3340 } |
| 3377 | 3341 |
| 3378 } // namespace test | 3342 } // namespace test |
| 3379 } // namespace views | 3343 } // namespace views |
| OLD | NEW |