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