Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(222)

Side by Side Diff: ash/wm/overview/window_selector_item.cc

Issue 2918403006: CrOS Tablet Window management - Split Screen part I (Closed)
Patch Set: Address oshima@'s comments Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
varkha 2017/06/21 01:51:53 nit: "Note:" or "Note that"
xdai1 2017/06/22 21:46:34 Done.
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:
varkha 2017/06/21 01:51:53 nit: "// views::CustomButton:" for consistency.
xdai1 2017/06/22 21:46:34 Done.
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 case ui::ET_GESTURE_SCROLL_UPDATE:
177 listener()->HandleDragEvent(location);
178 break;
179 case ui::ET_GESTURE_END:
180 listener()->HandleReleaseEvent(location);
181 break;
182 default:
183 break;
184 }
185 event->SetHandled();
186 return;
187 }
188 views::CustomButton::OnGestureEvent(event);
189 }
190
191 WindowSelectorItem* listener() {
192 return static_cast<WindowSelectorItem*>(listener_);
varkha 2017/06/21 01:51:53 Since this is a local class, I think it would look
xdai1 2017/06/22 21:46:34 |listener_| is a class member variable from the ba
varkha 2017/06/26 16:40:07 Acknowledged.
193 }
194
131 protected: 195 protected:
132 // views::View: 196 // views::View:
133 const char* GetClassName() const override { return "ShieldButton"; } 197 const char* GetClassName() const override { return "ShieldButton"; }
134 198
135 private: 199 private:
136 DISALLOW_COPY_AND_ASSIGN(ShieldButton); 200 DISALLOW_COPY_AND_ASSIGN(ShieldButton);
137 }; 201 };
138 202
139 } // namespace 203 } // namespace
140 204
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 views::Label* label_; 455 views::Label* label_;
392 views::ImageButton* close_button_; 456 views::ImageButton* close_button_;
393 457
394 DISALLOW_COPY_AND_ASSIGN(CaptionContainerView); 458 DISALLOW_COPY_AND_ASSIGN(CaptionContainerView);
395 }; 459 };
396 460
397 WindowSelectorItem::WindowSelectorItem(aura::Window* window, 461 WindowSelectorItem::WindowSelectorItem(aura::Window* window,
398 WindowSelector* window_selector) 462 WindowSelector* window_selector)
399 : dimmed_(false), 463 : dimmed_(false),
400 root_window_(window->GetRootWindow()), 464 root_window_(window->GetRootWindow()),
401 transform_window_(window), 465 transform_window_(this, window),
402 in_bounds_update_(false), 466 in_bounds_update_(false),
403 selected_(false), 467 selected_(false),
404 caption_container_view_(nullptr), 468 caption_container_view_(nullptr),
405 label_view_(nullptr), 469 label_view_(nullptr),
406 close_button_(new OverviewCloseButton(this)), 470 close_button_(new OverviewCloseButton(this)),
407 window_selector_(window_selector), 471 window_selector_(window_selector),
408 background_view_(nullptr) { 472 background_view_(nullptr) {
409 CreateWindowLabel(window->GetTitle()); 473 CreateWindowLabel(window->GetTitle());
410 GetWindow()->AddObserver(this); 474 GetWindow()->AddObserver(this);
411 } 475 }
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 } 591 }
528 592
529 void WindowSelectorItem::ButtonPressed(views::Button* sender, 593 void WindowSelectorItem::ButtonPressed(views::Button* sender,
530 const ui::Event& event) { 594 const ui::Event& event) {
531 if (sender == close_button_) { 595 if (sender == close_button_) {
532 ShellPort::Get()->RecordUserMetricsAction(UMA_WINDOW_OVERVIEW_CLOSE_BUTTON); 596 ShellPort::Get()->RecordUserMetricsAction(UMA_WINDOW_OVERVIEW_CLOSE_BUTTON);
533 CloseWindow(); 597 CloseWindow();
534 return; 598 return;
535 } 599 }
536 CHECK(sender == caption_container_view_->listener_button()); 600 CHECK(sender == caption_container_view_->listener_button());
537 window_selector_->SelectWindow(this); 601
602 // For other cases, the event is handled in OverviewWindowDragController.
603 if (!SplitViewController::ShouldAllowSplitView()) {
varkha 2017/06/21 01:51:53 nit: no {}
xdai1 2017/06/22 21:46:34 Done.
604 window_selector_->SelectWindow(this);
605 }
538 } 606 }
539 607
540 void WindowSelectorItem::OnWindowDestroying(aura::Window* window) { 608 void WindowSelectorItem::OnWindowDestroying(aura::Window* window) {
541 window->RemoveObserver(this); 609 window->RemoveObserver(this);
542 transform_window_.OnWindowDestroyed(); 610 transform_window_.OnWindowDestroyed();
543 } 611 }
544 612
545 void WindowSelectorItem::OnWindowTitleChanged(aura::Window* window) { 613 void WindowSelectorItem::OnWindowTitleChanged(aura::Window* window) {
546 // TODO(flackr): Maybe add the new title to a vector of titles so that we can 614 // 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. 615 // filter any of the titles the window had while in the overview session.
548 label_view_->SetText(window->GetTitle()); 616 label_view_->SetText(window->GetTitle());
549 UpdateAccessibilityName(); 617 UpdateAccessibilityName();
550 } 618 }
551 619
552 float WindowSelectorItem::GetItemScale(const gfx::Size& size) { 620 float WindowSelectorItem::GetItemScale(const gfx::Size& size) {
553 gfx::Size inset_size(size.width(), size.height() - 2 * kWindowMargin); 621 gfx::Size inset_size(size.width(), size.height() - 2 * kWindowMargin);
554 return ScopedTransformOverviewWindow::GetItemScale( 622 return ScopedTransformOverviewWindow::GetItemScale(
555 transform_window_.GetTargetBoundsInScreen().size(), inset_size, 623 transform_window_.GetTargetBoundsInScreen().size(), inset_size,
556 transform_window_.GetTopInset(), 624 transform_window_.GetTopInset(),
557 close_button_->GetPreferredSize().height()); 625 close_button_->GetPreferredSize().height());
558 } 626 }
559 627
628 void WindowSelectorItem::HandlePressEvent(
629 const gfx::Point& location_in_screen) {
630 PrepareDrag();
631 window_selector_->InitiateDrag(this, location_in_screen);
632 }
633
634 void WindowSelectorItem::HandleReleaseEvent(
635 const gfx::Point& location_in_screen) {
636 EndDrag();
637 window_selector_->CompleteDrag(this);
638 }
639
640 void WindowSelectorItem::HandleDragEvent(const gfx::Point& location_in_screen) {
641 window_selector_->Drag(this, location_in_screen);
642 }
643
560 gfx::Rect WindowSelectorItem::GetTargetBoundsInScreen() const { 644 gfx::Rect WindowSelectorItem::GetTargetBoundsInScreen() const {
561 return transform_window_.GetTargetBoundsInScreen(); 645 return transform_window_.GetTargetBoundsInScreen();
562 } 646 }
563 647
564 void WindowSelectorItem::SetItemBounds(const gfx::Rect& target_bounds, 648 void WindowSelectorItem::SetItemBounds(const gfx::Rect& target_bounds,
565 OverviewAnimationType animation_type) { 649 OverviewAnimationType animation_type) {
566 DCHECK(root_window_ == GetWindow()->GetRootWindow()); 650 DCHECK(root_window_ == GetWindow()->GetRootWindow());
567 gfx::Rect screen_rect = transform_window_.GetTargetBoundsInScreen(); 651 gfx::Rect screen_rect = transform_window_.GetTargetBoundsInScreen();
568 652
569 // Avoid division by zero by ensuring screen bounds is not empty. 653 // Avoid division by zero by ensuring screen bounds is not empty.
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
740 } 824 }
741 825
742 gfx::SlideAnimation* WindowSelectorItem::GetBackgroundViewAnimation() { 826 gfx::SlideAnimation* WindowSelectorItem::GetBackgroundViewAnimation() {
743 return background_view_ ? background_view_->animation() : nullptr; 827 return background_view_ ? background_view_->animation() : nullptr;
744 } 828 }
745 829
746 aura::Window* WindowSelectorItem::GetOverviewWindowForMinimizedStateForTest() { 830 aura::Window* WindowSelectorItem::GetOverviewWindowForMinimizedStateForTest() {
747 return transform_window_.GetOverviewWindowForMinimizedState(); 831 return transform_window_.GetOverviewWindowForMinimizedState();
748 } 832 }
749 833
834 void WindowSelectorItem::PrepareDrag() {
835 gfx::Rect scaled_bounds(target_bounds_);
836 scaled_bounds.Inset(-target_bounds_.width() * kDragWindowScale,
837 -target_bounds_.height() * kDragWindowScale);
838 OverviewAnimationType animation_type =
839 OverviewAnimationType::OVERVIEW_ANIMATION_CLOSING_SELECTOR_ITEM;
840 SetBounds(scaled_bounds, animation_type);
varkha 2017/06/21 01:51:53 Don't you need to revert this somewhere?
xdai1 2017/06/22 21:46:34 I don't think it's necessary since if the window w
varkha 2017/06/26 16:40:07 Acknowledged.
841
842 aura::Window* widget_window = item_widget_->GetNativeWindow();
843 if (widget_window && widget_window->parent() == GetWindow()->parent()) {
844 // TODO(xdai): This might not work if there is an always on top window.
845 // See crbug.com/733760.
846 widget_window->parent()->StackChildAtTop(widget_window);
847 widget_window->parent()->StackChildBelow(GetWindow(), widget_window);
848 }
849 }
850
851 void WindowSelectorItem::EndDrag() {
852 aura::Window* widget_window = item_widget_->GetNativeWindow();
853 if (widget_window && widget_window->parent() == GetWindow()->parent()) {
854 widget_window->parent()->StackChildAtBottom(widget_window);
varkha 2017/06/21 01:51:53 I don't think we should be changing the order rela
xdai1 2017/06/22 21:46:34 I changed the animation time and confirmed that th
855 widget_window->parent()->StackChildBelow(GetWindow(), widget_window);
856 }
857 }
858
750 } // namespace ash 859 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698