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 "ash/wm/overview/window_selector_item.h" | 5 #include "ash/wm/overview/window_selector_item.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "ash/metrics/user_metrics_action.h" | 10 #include "ash/metrics/user_metrics_action.h" |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
92 // Duration of background opacity transition for the selected label. | 92 // Duration of background opacity transition for the selected label. |
93 static const int kSelectorFadeInMilliseconds = 350; | 93 static const int kSelectorFadeInMilliseconds = 350; |
94 | 94 |
95 // Duration of background opacity transition when exiting overview mode. | 95 // Duration of background opacity transition when exiting overview mode. |
96 static const int kExitFadeInMilliseconds = 30; | 96 static const int kExitFadeInMilliseconds = 30; |
97 | 97 |
98 // Before closing a window animate both the window and the caption to shrink by | 98 // Before closing a window animate both the window and the caption to shrink by |
99 // this fraction of size. | 99 // this fraction of size. |
100 static const float kPreCloseScale = 0.02f; | 100 static const float kPreCloseScale = 0.02f; |
101 | 101 |
102 // Before dragging an overview window, the window will scale up |kPreDragScale| | |
103 // to indicate its selection. | |
104 static const float kDragWindowScale = 0.04f; | |
105 | |
102 // Convenience method to fade in a Window with predefined animation settings. | 106 // Convenience method to fade in a Window with predefined animation settings. |
103 // Note: The fade in animation will occur after a delay where the delay is how | 107 // Note: The fade in animation will occur after a delay where the delay is how |
104 // long the lay out animations take. | 108 // long the lay out animations take. |
105 void SetupFadeInAfterLayout(views::Widget* widget) { | 109 void SetupFadeInAfterLayout(views::Widget* widget) { |
106 aura::Window* window = widget->GetNativeWindow(); | 110 aura::Window* window = widget->GetNativeWindow(); |
107 window->layer()->SetOpacity(0.0f); | 111 window->layer()->SetOpacity(0.0f); |
108 ScopedOverviewAnimationSettings scoped_overview_animation_settings( | 112 ScopedOverviewAnimationSettings scoped_overview_animation_settings( |
109 OverviewAnimationType::OVERVIEW_ANIMATION_ENTER_OVERVIEW_MODE_FADE_IN, | 113 OverviewAnimationType::OVERVIEW_ANIMATION_ENTER_OVERVIEW_MODE_FADE_IN, |
110 window); | 114 window); |
111 window->layer()->SetOpacity(1.0f); | 115 window->layer()->SetOpacity(1.0f); |
112 } | 116 } |
113 | 117 |
114 // A Button that has a listener and listens to mouse clicks on the visible part | 118 // A Button that has a listener and listens to mouse / gesture events on the |
115 // of an overview window. | 119 // visible part of an overview window. Note the drag events are only handled in |
120 // maximized mode. | |
116 class ShieldButton : public views::CustomButton { | 121 class ShieldButton : public views::CustomButton { |
117 public: | 122 public: |
118 ShieldButton(views::ButtonListener* listener, const base::string16& name) | 123 ShieldButton(views::ButtonListener* listener, const base::string16& name) |
119 : views::CustomButton(listener) { | 124 : views::CustomButton(listener) { |
120 SetAccessibleName(name); | 125 SetAccessibleName(name); |
121 } | 126 } |
122 ~ShieldButton() override {} | 127 ~ShieldButton() override {} |
123 | 128 |
124 // When WindowSelectorItem (which is a ButtonListener) is destroyed, its | 129 // When WindowSelectorItem (which is a ButtonListener) is destroyed, its |
125 // |item_widget_| is allowed to stay around to complete any animations. | 130 // |item_widget_| is allowed to stay around to complete any animations. |
126 // Resetting the listener in all views that are targeted by events is | 131 // Resetting the listener in all views that are targeted by events is |
127 // necessary to prevent a crash when a user clicks on the fading out widget | 132 // necessary to prevent a crash when a user clicks on the fading out widget |
128 // after the WindowSelectorItem has been destroyed. | 133 // after the WindowSelectorItem has been destroyed. |
129 void ResetListener() { listener_ = nullptr; } | 134 void ResetListener() { listener_ = nullptr; } |
130 | 135 |
136 // views::CustomButton overrides: | |
137 bool OnMousePressed(const ui::MouseEvent& event) override { | |
138 if (listener() && SplitViewController::ShouldAllowSplitView()) { | |
139 gfx::Point location(event.location()); | |
140 views::View::ConvertPointToScreen(this, &location); | |
141 listener()->HandlePressEvent(location); | |
142 return true; | |
143 } | |
144 return views::CustomButton::OnMousePressed(event); | |
145 } | |
146 | |
147 void OnMouseReleased(const ui::MouseEvent& event) override { | |
148 if (listener() && SplitViewController::ShouldAllowSplitView()) { | |
149 gfx::Point location(event.location()); | |
150 views::View::ConvertPointToScreen(this, &location); | |
151 listener()->HandleReleaseEvent(location); | |
152 return; | |
153 } | |
154 views::CustomButton::OnMouseReleased(event); | |
155 } | |
156 | |
157 bool OnMouseDragged(const ui::MouseEvent& event) override { | |
158 if (listener() && SplitViewController::ShouldAllowSplitView()) { | |
159 gfx::Point location(event.location()); | |
160 views::View::ConvertPointToScreen(this, &location); | |
161 listener()->HandleDragEvent(location); | |
162 return true; | |
163 } | |
164 return views::CustomButton::OnMouseDragged(event); | |
165 } | |
166 | |
167 void OnGestureEvent(ui::GestureEvent* event) override { | |
168 if (listener() && SplitViewController::ShouldAllowSplitView()) { | |
169 gfx::Point location(event->location()); | |
170 views::View::ConvertPointToScreen(this, &location); | |
171 switch (event->type()) { | |
172 case ui::ET_GESTURE_SCROLL_BEGIN: | |
173 case ui::ET_GESTURE_TAP_DOWN: { | |
174 listener()->HandlePressEvent(location); | |
175 break; | |
176 } | |
oshima
2017/06/16 19:39:15
nit: nuke {}
xdai1
2017/06/16 20:01:46
Done.
| |
177 case ui::ET_GESTURE_SCROLL_UPDATE: | |
178 listener()->HandleDragEvent(location); | |
179 break; | |
180 case ui::ET_GESTURE_END: | |
181 listener()->HandleReleaseEvent(location); | |
182 break; | |
183 default: | |
184 break; | |
185 } | |
186 event->SetHandled(); | |
187 return; | |
188 } | |
189 views::CustomButton::OnGestureEvent(event); | |
190 } | |
191 | |
192 WindowSelectorItem* listener() { | |
193 return static_cast<WindowSelectorItem*>(listener_); | |
194 } | |
195 | |
131 protected: | 196 protected: |
132 // views::View: | 197 // views::View: |
133 const char* GetClassName() const override { return "ShieldButton"; } | 198 const char* GetClassName() const override { return "ShieldButton"; } |
134 | 199 |
135 private: | 200 private: |
136 DISALLOW_COPY_AND_ASSIGN(ShieldButton); | 201 DISALLOW_COPY_AND_ASSIGN(ShieldButton); |
137 }; | 202 }; |
138 | 203 |
139 } // namespace | 204 } // namespace |
140 | 205 |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
391 views::Label* label_; | 456 views::Label* label_; |
392 views::ImageButton* close_button_; | 457 views::ImageButton* close_button_; |
393 | 458 |
394 DISALLOW_COPY_AND_ASSIGN(CaptionContainerView); | 459 DISALLOW_COPY_AND_ASSIGN(CaptionContainerView); |
395 }; | 460 }; |
396 | 461 |
397 WindowSelectorItem::WindowSelectorItem(aura::Window* window, | 462 WindowSelectorItem::WindowSelectorItem(aura::Window* window, |
398 WindowSelector* window_selector) | 463 WindowSelector* window_selector) |
399 : dimmed_(false), | 464 : dimmed_(false), |
400 root_window_(window->GetRootWindow()), | 465 root_window_(window->GetRootWindow()), |
401 transform_window_(window), | 466 transform_window_(this, window), |
402 in_bounds_update_(false), | 467 in_bounds_update_(false), |
403 selected_(false), | 468 selected_(false), |
404 caption_container_view_(nullptr), | 469 caption_container_view_(nullptr), |
405 label_view_(nullptr), | 470 label_view_(nullptr), |
406 close_button_(new OverviewCloseButton(this)), | 471 close_button_(new OverviewCloseButton(this)), |
407 window_selector_(window_selector), | 472 window_selector_(window_selector), |
408 background_view_(nullptr) { | 473 background_view_(nullptr) { |
409 CreateWindowLabel(window->GetTitle()); | 474 CreateWindowLabel(window->GetTitle()); |
410 GetWindow()->AddObserver(this); | 475 GetWindow()->AddObserver(this); |
411 } | 476 } |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
527 } | 592 } |
528 | 593 |
529 void WindowSelectorItem::ButtonPressed(views::Button* sender, | 594 void WindowSelectorItem::ButtonPressed(views::Button* sender, |
530 const ui::Event& event) { | 595 const ui::Event& event) { |
531 if (sender == close_button_) { | 596 if (sender == close_button_) { |
532 ShellPort::Get()->RecordUserMetricsAction(UMA_WINDOW_OVERVIEW_CLOSE_BUTTON); | 597 ShellPort::Get()->RecordUserMetricsAction(UMA_WINDOW_OVERVIEW_CLOSE_BUTTON); |
533 CloseWindow(); | 598 CloseWindow(); |
534 return; | 599 return; |
535 } | 600 } |
536 CHECK(sender == caption_container_view_->listener_button()); | 601 CHECK(sender == caption_container_view_->listener_button()); |
537 window_selector_->SelectWindow(this); | 602 |
603 // For other cases, the event is handled in OverviewWindowDragController. | |
604 if (!SplitViewController::ShouldAllowSplitView()) { | |
605 window_selector_->SelectWindow(this); | |
606 } | |
538 } | 607 } |
539 | 608 |
540 void WindowSelectorItem::OnWindowDestroying(aura::Window* window) { | 609 void WindowSelectorItem::OnWindowDestroying(aura::Window* window) { |
541 window->RemoveObserver(this); | 610 window->RemoveObserver(this); |
542 transform_window_.OnWindowDestroyed(); | 611 transform_window_.OnWindowDestroyed(); |
543 } | 612 } |
544 | 613 |
545 void WindowSelectorItem::OnWindowTitleChanged(aura::Window* window) { | 614 void WindowSelectorItem::OnWindowTitleChanged(aura::Window* window) { |
546 // TODO(flackr): Maybe add the new title to a vector of titles so that we can | 615 // TODO(flackr): Maybe add the new title to a vector of titles so that we can |
547 // filter any of the titles the window had while in the overview session. | 616 // filter any of the titles the window had while in the overview session. |
548 label_view_->SetText(window->GetTitle()); | 617 label_view_->SetText(window->GetTitle()); |
549 UpdateAccessibilityName(); | 618 UpdateAccessibilityName(); |
550 } | 619 } |
551 | 620 |
552 float WindowSelectorItem::GetItemScale(const gfx::Size& size) { | 621 float WindowSelectorItem::GetItemScale(const gfx::Size& size) { |
553 gfx::Size inset_size(size.width(), size.height() - 2 * kWindowMargin); | 622 gfx::Size inset_size(size.width(), size.height() - 2 * kWindowMargin); |
554 return ScopedTransformOverviewWindow::GetItemScale( | 623 return ScopedTransformOverviewWindow::GetItemScale( |
555 transform_window_.GetTargetBoundsInScreen().size(), inset_size, | 624 transform_window_.GetTargetBoundsInScreen().size(), inset_size, |
556 transform_window_.GetTopInset(), | 625 transform_window_.GetTopInset(), |
557 close_button_->GetPreferredSize().height()); | 626 close_button_->GetPreferredSize().height()); |
558 } | 627 } |
559 | 628 |
629 void WindowSelectorItem::HandlePressEvent( | |
630 const gfx::Point& location_in_screen) { | |
631 PrepareDrag(); | |
632 window_selector_->InitiateDrag(this, location_in_screen); | |
633 } | |
634 | |
635 void WindowSelectorItem::HandleReleaseEvent( | |
636 const gfx::Point& location_in_screen) { | |
637 EndDrag(); | |
638 window_selector_->CompleteDrag(this); | |
639 } | |
640 | |
641 void WindowSelectorItem::HandleDragEvent(const gfx::Point& location_in_screen) { | |
642 window_selector_->Drag(this, location_in_screen); | |
643 } | |
644 | |
560 gfx::Rect WindowSelectorItem::GetTargetBoundsInScreen() const { | 645 gfx::Rect WindowSelectorItem::GetTargetBoundsInScreen() const { |
561 return transform_window_.GetTargetBoundsInScreen(); | 646 return transform_window_.GetTargetBoundsInScreen(); |
562 } | 647 } |
563 | 648 |
564 void WindowSelectorItem::SetItemBounds(const gfx::Rect& target_bounds, | 649 void WindowSelectorItem::SetItemBounds(const gfx::Rect& target_bounds, |
565 OverviewAnimationType animation_type) { | 650 OverviewAnimationType animation_type) { |
566 DCHECK(root_window_ == GetWindow()->GetRootWindow()); | 651 DCHECK(root_window_ == GetWindow()->GetRootWindow()); |
567 gfx::Rect screen_rect = transform_window_.GetTargetBoundsInScreen(); | 652 gfx::Rect screen_rect = transform_window_.GetTargetBoundsInScreen(); |
568 | 653 |
569 // Avoid division by zero by ensuring screen bounds is not empty. | 654 // Avoid division by zero by ensuring screen bounds is not empty. |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
740 } | 825 } |
741 | 826 |
742 gfx::SlideAnimation* WindowSelectorItem::GetBackgroundViewAnimation() { | 827 gfx::SlideAnimation* WindowSelectorItem::GetBackgroundViewAnimation() { |
743 return background_view_ ? background_view_->animation() : nullptr; | 828 return background_view_ ? background_view_->animation() : nullptr; |
744 } | 829 } |
745 | 830 |
746 aura::Window* WindowSelectorItem::GetOverviewWindowForMinimizedStateForTest() { | 831 aura::Window* WindowSelectorItem::GetOverviewWindowForMinimizedStateForTest() { |
747 return transform_window_.GetOverviewWindowForMinimizedState(); | 832 return transform_window_.GetOverviewWindowForMinimizedState(); |
748 } | 833 } |
749 | 834 |
835 void WindowSelectorItem::PrepareDrag() { | |
836 gfx::Rect scaled_bounds(target_bounds_); | |
837 scaled_bounds.Inset(-target_bounds_.width() * kDragWindowScale, | |
838 -target_bounds_.height() * kDragWindowScale); | |
839 OverviewAnimationType animation_type = | |
840 OverviewAnimationType::OVERVIEW_ANIMATION_CLOSING_SELECTOR_ITEM; | |
841 SetBounds(scaled_bounds, animation_type); | |
842 | |
843 aura::Window* widget_window = item_widget_->GetNativeWindow(); | |
844 if (widget_window && widget_window->parent() == GetWindow()->parent()) { | |
845 // TODO(xdai): This might not work if there is an always on top window. | |
846 // See crbug.com/733760. | |
847 widget_window->parent()->StackChildAtTop(widget_window); | |
848 widget_window->parent()->StackChildBelow(GetWindow(), widget_window); | |
849 } | |
850 } | |
851 | |
852 void WindowSelectorItem::EndDrag() { | |
853 aura::Window* widget_window = item_widget_->GetNativeWindow(); | |
854 if (widget_window && widget_window->parent() == GetWindow()->parent()) { | |
855 widget_window->parent()->StackChildAtBottom(widget_window); | |
856 widget_window->parent()->StackChildBelow(GetWindow(), widget_window); | |
857 } | |
858 } | |
859 | |
750 } // namespace ash | 860 } // namespace ash |
OLD | NEW |