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

Side by Side Diff: ash/wm/panels/panel_layout_manager.cc

Issue 1877543002: Revise the shelf alignment locking mechanism. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update and cleanup tests. Created 4 years, 8 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 (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 "ash/wm/panels/panel_layout_manager.h" 5 #include "ash/wm/panels/panel_layout_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 63
64 class CalloutWidgetBackground : public views::Background { 64 class CalloutWidgetBackground : public views::Background {
65 public: 65 public:
66 CalloutWidgetBackground() : alignment_(SHELF_ALIGNMENT_BOTTOM) { 66 CalloutWidgetBackground() : alignment_(SHELF_ALIGNMENT_BOTTOM) {
67 } 67 }
68 68
69 void Paint(gfx::Canvas* canvas, views::View* view) const override { 69 void Paint(gfx::Canvas* canvas, views::View* view) const override {
70 SkPath path; 70 SkPath path;
71 switch (alignment_) { 71 switch (alignment_) {
72 case SHELF_ALIGNMENT_BOTTOM: 72 case SHELF_ALIGNMENT_BOTTOM:
73 case SHELF_ALIGNMENT_BOTTOM_LOCKED:
73 path.moveTo(SkIntToScalar(0), SkIntToScalar(0)); 74 path.moveTo(SkIntToScalar(0), SkIntToScalar(0));
74 path.lineTo(SkIntToScalar(kArrowWidth / 2), 75 path.lineTo(SkIntToScalar(kArrowWidth / 2),
75 SkIntToScalar(kArrowHeight)); 76 SkIntToScalar(kArrowHeight));
76 path.lineTo(SkIntToScalar(kArrowWidth), SkIntToScalar(0)); 77 path.lineTo(SkIntToScalar(kArrowWidth), SkIntToScalar(0));
77 break; 78 break;
78 case SHELF_ALIGNMENT_LEFT: 79 case SHELF_ALIGNMENT_LEFT:
79 path.moveTo(SkIntToScalar(kArrowHeight), SkIntToScalar(kArrowWidth)); 80 path.moveTo(SkIntToScalar(kArrowHeight), SkIntToScalar(kArrowWidth));
80 path.lineTo(SkIntToScalar(0), SkIntToScalar(kArrowWidth / 2)); 81 path.lineTo(SkIntToScalar(0), SkIntToScalar(kArrowWidth / 2));
81 path.lineTo(SkIntToScalar(kArrowHeight), SkIntToScalar(0)); 82 path.lineTo(SkIntToScalar(kArrowHeight), SkIntToScalar(0));
82 break; 83 break;
83 case SHELF_ALIGNMENT_RIGHT: 84 case SHELF_ALIGNMENT_RIGHT:
84 path.moveTo(SkIntToScalar(0), SkIntToScalar(0)); 85 path.moveTo(SkIntToScalar(0), SkIntToScalar(0));
85 path.lineTo(SkIntToScalar(kArrowHeight), 86 path.lineTo(SkIntToScalar(kArrowHeight),
86 SkIntToScalar(kArrowWidth / 2)); 87 SkIntToScalar(kArrowWidth / 2));
87 path.lineTo(SkIntToScalar(0), SkIntToScalar(kArrowWidth)); 88 path.lineTo(SkIntToScalar(0), SkIntToScalar(kArrowWidth));
88 break; 89 break;
89 } 90 }
90 // Hard code the arrow color for now. 91 // Hard code the arrow color for now.
91 SkPaint paint; 92 SkPaint paint;
92 paint.setStyle(SkPaint::kFill_Style); 93 paint.setStyle(SkPaint::kFill_Style);
93 paint.setColor(SkColorSetARGB(0xff, 0xe5, 0xe5, 0xe5)); 94 paint.setColor(SkColorSetARGB(0xff, 0xe5, 0xe5, 0xe5));
94 canvas->DrawPath(path, paint); 95 canvas->DrawPath(path, paint);
95 } 96 }
96 97
97 ShelfAlignment alignment() { 98 ShelfAlignment alignment() { return alignment_; }
98 return alignment_;
99 }
100 99
101 void set_alignment(ShelfAlignment alignment) { 100 void set_alignment(ShelfAlignment alignment) { alignment_ = alignment; }
102 alignment_ = alignment;
103 }
104 101
105 private: 102 private:
106 ShelfAlignment alignment_; 103 ShelfAlignment alignment_;
107 104
108 DISALLOW_COPY_AND_ASSIGN(CalloutWidgetBackground); 105 DISALLOW_COPY_AND_ASSIGN(CalloutWidgetBackground);
109 }; 106 };
110 107
111 struct VisiblePanelPositionInfo { 108 struct VisiblePanelPositionInfo {
112 VisiblePanelPositionInfo() 109 VisiblePanelPositionInfo()
113 : min_major(0), 110 : min_major(0),
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 169
173 bool BoundsAdjacent(const gfx::Rect& bounds1, const gfx::Rect& bounds2) { 170 bool BoundsAdjacent(const gfx::Rect& bounds1, const gfx::Rect& bounds2) {
174 return bounds1.x() == bounds2.right() || 171 return bounds1.x() == bounds2.right() ||
175 bounds1.y() == bounds2.bottom() || 172 bounds1.y() == bounds2.bottom() ||
176 bounds1.right() == bounds2.x() || 173 bounds1.right() == bounds2.x() ||
177 bounds1.bottom() == bounds2.y(); 174 bounds1.bottom() == bounds2.y();
178 } 175 }
179 176
180 gfx::Vector2d GetSlideInAnimationOffset(ShelfAlignment alignment) { 177 gfx::Vector2d GetSlideInAnimationOffset(ShelfAlignment alignment) {
181 gfx::Vector2d offset; 178 gfx::Vector2d offset;
182 switch (alignment) { 179 if (alignment == SHELF_ALIGNMENT_LEFT)
183 case SHELF_ALIGNMENT_BOTTOM: 180 offset.set_x(-kPanelSlideInOffset);
184 offset.set_y(kPanelSlideInOffset); 181 else if (alignment == SHELF_ALIGNMENT_RIGHT)
185 break; 182 offset.set_x(kPanelSlideInOffset);
186 case SHELF_ALIGNMENT_LEFT: 183 else
187 offset.set_x(-kPanelSlideInOffset); 184 offset.set_y(kPanelSlideInOffset);
188 break;
189 case SHELF_ALIGNMENT_RIGHT:
190 offset.set_x(kPanelSlideInOffset);
191 break;
192 }
193 return offset; 185 return offset;
194 } 186 }
195 187
196 } // namespace 188 } // namespace
197 189
198 class PanelCalloutWidget : public views::Widget { 190 class PanelCalloutWidget : public views::Widget {
199 public: 191 public:
200 explicit PanelCalloutWidget(aura::Window* container) 192 explicit PanelCalloutWidget(aura::Window* container)
201 : background_(NULL) { 193 : background_(NULL) {
202 InitWidget(container); 194 InitWidget(container);
203 } 195 }
204 196
205 void SetAlignment(ShelfAlignment alignment) { 197 void SetAlignment(ShelfAlignment alignment) {
206 gfx::Rect callout_bounds = GetWindowBoundsInScreen(); 198 gfx::Rect callout_bounds = GetWindowBoundsInScreen();
207 if (alignment == SHELF_ALIGNMENT_BOTTOM) { 199 if (IsHorizontalAlignment(alignment)) {
208 callout_bounds.set_width(kArrowWidth); 200 callout_bounds.set_width(kArrowWidth);
209 callout_bounds.set_height(kArrowHeight); 201 callout_bounds.set_height(kArrowHeight);
210 } else { 202 } else {
211 callout_bounds.set_width(kArrowHeight); 203 callout_bounds.set_width(kArrowHeight);
212 callout_bounds.set_height(kArrowWidth); 204 callout_bounds.set_height(kArrowWidth);
213 } 205 }
214 GetNativeWindow()->SetBounds(callout_bounds); 206 GetNativeWindow()->SetBounds(callout_bounds);
215 if (background_->alignment() != alignment) { 207 if (background_->alignment() != alignment) {
216 background_->set_alignment(alignment); 208 background_->set_alignment(alignment);
217 SchedulePaintInRect(gfx::Rect(gfx::Point(), callout_bounds.size())); 209 SchedulePaintInRect(gfx::Rect(gfx::Point(), callout_bounds.size()));
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after
697 } 689 }
698 } 690 }
699 FanOutPanels(visible_panels.begin() + first_overlapping_panel, 691 FanOutPanels(visible_panels.begin() + first_overlapping_panel,
700 visible_panels.end()); 692 visible_panels.end());
701 693
702 for (size_t i = 0; i < visible_panels.size(); ++i) { 694 for (size_t i = 0; i < visible_panels.size(); ++i) {
703 if (visible_panels[i].window == dragged_panel_) 695 if (visible_panels[i].window == dragged_panel_)
704 continue; 696 continue;
705 bool slide_in = visible_panels[i].slide_in; 697 bool slide_in = visible_panels[i].slide_in;
706 gfx::Rect bounds = visible_panels[i].window->GetTargetBounds(); 698 gfx::Rect bounds = visible_panels[i].window->GetTargetBounds();
707 switch (alignment) { 699 if (alignment == SHELF_ALIGNMENT_LEFT)
708 case SHELF_ALIGNMENT_BOTTOM: 700 bounds.set_x(shelf_bounds.right());
709 bounds.set_y(shelf_bounds.y() - bounds.height()); 701 else if (alignment == SHELF_ALIGNMENT_RIGHT)
710 break; 702 bounds.set_x(shelf_bounds.x() - bounds.width());
711 case SHELF_ALIGNMENT_LEFT: 703 else
712 bounds.set_x(shelf_bounds.right()); 704 bounds.set_y(shelf_bounds.y() - bounds.height());
713 break;
714 case SHELF_ALIGNMENT_RIGHT:
715 bounds.set_x(shelf_bounds.x() - bounds.width());
716 break;
717 }
718 bool on_shelf = visible_panels[i].window->GetTargetBounds() == bounds; 705 bool on_shelf = visible_panels[i].window->GetTargetBounds() == bounds;
719 706
720 if (horizontal) { 707 if (horizontal) {
721 bounds.set_x(visible_panels[i].major_pos - 708 bounds.set_x(visible_panels[i].major_pos -
722 visible_panels[i].major_length / 2); 709 visible_panels[i].major_length / 2);
723 } else { 710 } else {
724 bounds.set_y(visible_panels[i].major_pos - 711 bounds.set_y(visible_panels[i].major_pos -
725 visible_panels[i].major_length / 2); 712 visible_panels[i].major_length / 2);
726 } 713 }
727 714
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
840 current_bounds.x() - callout_bounds.x(), 827 current_bounds.x() - callout_bounds.x(),
841 callout_bounds.right() - current_bounds.right()); 828 callout_bounds.right() - current_bounds.right());
842 } else { 829 } else {
843 callout_bounds.set_y( 830 callout_bounds.set_y(
844 icon_bounds.y() + (icon_bounds.height() - 831 icon_bounds.y() + (icon_bounds.height() -
845 callout_bounds.height()) / 2); 832 callout_bounds.height()) / 2);
846 distance_until_over_panel = std::max( 833 distance_until_over_panel = std::max(
847 current_bounds.y() - callout_bounds.y(), 834 current_bounds.y() - callout_bounds.y(),
848 callout_bounds.bottom() - current_bounds.bottom()); 835 callout_bounds.bottom() - current_bounds.bottom());
849 } 836 }
850 switch (shelf_->alignment()) { 837 if (shelf_->alignment() == SHELF_ALIGNMENT_LEFT)
851 case SHELF_ALIGNMENT_BOTTOM: 838 callout_bounds.set_x(bounds.x() - callout_bounds.width());
852 callout_bounds.set_y(bounds.bottom()); 839 else if (shelf_->alignment() == SHELF_ALIGNMENT_RIGHT)
853 break; 840 callout_bounds.set_x(bounds.right());
854 case SHELF_ALIGNMENT_LEFT: 841 else
855 callout_bounds.set_x(bounds.x() - callout_bounds.width()); 842 callout_bounds.set_y(bounds.bottom());
856 break;
857 case SHELF_ALIGNMENT_RIGHT:
858 callout_bounds.set_x(bounds.right());
859 break;
860 }
861 callout_bounds = ScreenUtil::ConvertRectFromScreen( 843 callout_bounds = ScreenUtil::ConvertRectFromScreen(
862 callout_widget->GetNativeWindow()->parent(), 844 callout_widget->GetNativeWindow()->parent(),
863 callout_bounds); 845 callout_bounds);
864 846
865 SetChildBoundsDirect(callout_widget->GetNativeWindow(), callout_bounds); 847 SetChildBoundsDirect(callout_widget->GetNativeWindow(), callout_bounds);
866 panel_container_->StackChildAbove(callout_widget->GetNativeWindow(), 848 panel_container_->StackChildAbove(callout_widget->GetNativeWindow(),
867 panel); 849 panel);
868 850
869 ui::Layer* layer = callout_widget->GetNativeWindow()->layer(); 851 ui::Layer* layer = callout_widget->GetNativeWindow()->layer();
870 // If the panel is not over the callout position or has just become visible 852 // If the panel is not over the callout position or has just become visible
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
930 // Keyboard hidden, restore original bounds if they exist. 912 // Keyboard hidden, restore original bounds if they exist.
931 SetChildBounds(panel, panel_state->GetRestoreBoundsInScreen()); 913 SetChildBounds(panel, panel_state->GetRestoreBoundsInScreen());
932 } 914 }
933 } 915 }
934 // This bounds change will have caused a change to the Shelf which does not 916 // This bounds change will have caused a change to the Shelf which does not
935 // propogate automatically to this class, so manually recalculate bounds. 917 // propogate automatically to this class, so manually recalculate bounds.
936 OnWindowResized(); 918 OnWindowResized();
937 } 919 }
938 920
939 } // namespace ash 921 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/panels/attached_panel_window_targeter.cc ('k') | ash/wm/panels/panel_layout_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698