| 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 // Offset used when sliding panel in/out of the shelf. Used for minimizing, | 52 // Offset used when sliding panel in/out of the shelf. Used for minimizing, |
| 53 // restoring and the initial showing of a panel. | 53 // restoring and the initial showing of a panel. |
| 54 const int kPanelSlideInOffset = 20; | 54 const int kPanelSlideInOffset = 20; |
| 55 | 55 |
| 56 // Callout arrow dimensions. | 56 // Callout arrow dimensions. |
| 57 const int kArrowWidth = 18; | 57 const int kArrowWidth = 18; |
| 58 const int kArrowHeight = 9; | 58 const int kArrowHeight = 9; |
| 59 | 59 |
| 60 class CalloutWidgetBackground : public views::Background { | 60 class CalloutWidgetBackground : public views::Background { |
| 61 public: | 61 public: |
| 62 CalloutWidgetBackground() : alignment_(SHELF_ALIGNMENT_BOTTOM) { | 62 CalloutWidgetBackground() : alignment_(wm::SHELF_ALIGNMENT_BOTTOM) {} |
| 63 } | |
| 64 | 63 |
| 65 void Paint(gfx::Canvas* canvas, views::View* view) const override { | 64 void Paint(gfx::Canvas* canvas, views::View* view) const override { |
| 66 SkPath path; | 65 SkPath path; |
| 67 switch (alignment_) { | 66 switch (alignment_) { |
| 68 case SHELF_ALIGNMENT_BOTTOM: | 67 case wm::SHELF_ALIGNMENT_BOTTOM: |
| 69 case SHELF_ALIGNMENT_BOTTOM_LOCKED: | 68 case wm::SHELF_ALIGNMENT_BOTTOM_LOCKED: |
| 70 path.moveTo(SkIntToScalar(0), SkIntToScalar(0)); | 69 path.moveTo(SkIntToScalar(0), SkIntToScalar(0)); |
| 71 path.lineTo(SkIntToScalar(kArrowWidth / 2), | 70 path.lineTo(SkIntToScalar(kArrowWidth / 2), |
| 72 SkIntToScalar(kArrowHeight)); | 71 SkIntToScalar(kArrowHeight)); |
| 73 path.lineTo(SkIntToScalar(kArrowWidth), SkIntToScalar(0)); | 72 path.lineTo(SkIntToScalar(kArrowWidth), SkIntToScalar(0)); |
| 74 break; | 73 break; |
| 75 case SHELF_ALIGNMENT_LEFT: | 74 case wm::SHELF_ALIGNMENT_LEFT: |
| 76 path.moveTo(SkIntToScalar(kArrowHeight), SkIntToScalar(kArrowWidth)); | 75 path.moveTo(SkIntToScalar(kArrowHeight), SkIntToScalar(kArrowWidth)); |
| 77 path.lineTo(SkIntToScalar(0), SkIntToScalar(kArrowWidth / 2)); | 76 path.lineTo(SkIntToScalar(0), SkIntToScalar(kArrowWidth / 2)); |
| 78 path.lineTo(SkIntToScalar(kArrowHeight), SkIntToScalar(0)); | 77 path.lineTo(SkIntToScalar(kArrowHeight), SkIntToScalar(0)); |
| 79 break; | 78 break; |
| 80 case SHELF_ALIGNMENT_RIGHT: | 79 case wm::SHELF_ALIGNMENT_RIGHT: |
| 81 path.moveTo(SkIntToScalar(0), SkIntToScalar(0)); | 80 path.moveTo(SkIntToScalar(0), SkIntToScalar(0)); |
| 82 path.lineTo(SkIntToScalar(kArrowHeight), | 81 path.lineTo(SkIntToScalar(kArrowHeight), |
| 83 SkIntToScalar(kArrowWidth / 2)); | 82 SkIntToScalar(kArrowWidth / 2)); |
| 84 path.lineTo(SkIntToScalar(0), SkIntToScalar(kArrowWidth)); | 83 path.lineTo(SkIntToScalar(0), SkIntToScalar(kArrowWidth)); |
| 85 break; | 84 break; |
| 86 } | 85 } |
| 87 // Hard code the arrow color for now. | 86 // Hard code the arrow color for now. |
| 88 SkPaint paint; | 87 SkPaint paint; |
| 89 paint.setStyle(SkPaint::kFill_Style); | 88 paint.setStyle(SkPaint::kFill_Style); |
| 90 paint.setColor(SkColorSetARGB(0xff, 0xe5, 0xe5, 0xe5)); | 89 paint.setColor(SkColorSetARGB(0xff, 0xe5, 0xe5, 0xe5)); |
| 91 canvas->DrawPath(path, paint); | 90 canvas->DrawPath(path, paint); |
| 92 } | 91 } |
| 93 | 92 |
| 94 ShelfAlignment alignment() { return alignment_; } | 93 wm::ShelfAlignment alignment() { return alignment_; } |
| 95 | 94 |
| 96 void set_alignment(ShelfAlignment alignment) { alignment_ = alignment; } | 95 void set_alignment(wm::ShelfAlignment alignment) { alignment_ = alignment; } |
| 97 | 96 |
| 98 private: | 97 private: |
| 99 ShelfAlignment alignment_; | 98 wm::ShelfAlignment alignment_; |
| 100 | 99 |
| 101 DISALLOW_COPY_AND_ASSIGN(CalloutWidgetBackground); | 100 DISALLOW_COPY_AND_ASSIGN(CalloutWidgetBackground); |
| 102 }; | 101 }; |
| 103 | 102 |
| 104 struct VisiblePanelPositionInfo { | 103 struct VisiblePanelPositionInfo { |
| 105 VisiblePanelPositionInfo() | 104 VisiblePanelPositionInfo() |
| 106 : min_major(0), | 105 : min_major(0), |
| 107 max_major(0), | 106 max_major(0), |
| 108 major_pos(0), | 107 major_pos(0), |
| 109 major_length(0), | 108 major_length(0), |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 } | 162 } |
| 164 } | 163 } |
| 165 | 164 |
| 166 bool BoundsAdjacent(const gfx::Rect& bounds1, const gfx::Rect& bounds2) { | 165 bool BoundsAdjacent(const gfx::Rect& bounds1, const gfx::Rect& bounds2) { |
| 167 return bounds1.x() == bounds2.right() || | 166 return bounds1.x() == bounds2.right() || |
| 168 bounds1.y() == bounds2.bottom() || | 167 bounds1.y() == bounds2.bottom() || |
| 169 bounds1.right() == bounds2.x() || | 168 bounds1.right() == bounds2.x() || |
| 170 bounds1.bottom() == bounds2.y(); | 169 bounds1.bottom() == bounds2.y(); |
| 171 } | 170 } |
| 172 | 171 |
| 173 gfx::Vector2d GetSlideInAnimationOffset(ShelfAlignment alignment) { | 172 gfx::Vector2d GetSlideInAnimationOffset(wm::ShelfAlignment alignment) { |
| 174 gfx::Vector2d offset; | 173 gfx::Vector2d offset; |
| 175 if (alignment == SHELF_ALIGNMENT_LEFT) | 174 if (alignment == wm::SHELF_ALIGNMENT_LEFT) |
| 176 offset.set_x(-kPanelSlideInOffset); | 175 offset.set_x(-kPanelSlideInOffset); |
| 177 else if (alignment == SHELF_ALIGNMENT_RIGHT) | 176 else if (alignment == wm::SHELF_ALIGNMENT_RIGHT) |
| 178 offset.set_x(kPanelSlideInOffset); | 177 offset.set_x(kPanelSlideInOffset); |
| 179 else | 178 else |
| 180 offset.set_y(kPanelSlideInOffset); | 179 offset.set_y(kPanelSlideInOffset); |
| 181 return offset; | 180 return offset; |
| 182 } | 181 } |
| 183 | 182 |
| 184 } // namespace | 183 } // namespace |
| 185 | 184 |
| 186 class PanelCalloutWidget : public views::Widget { | 185 class PanelCalloutWidget : public views::Widget { |
| 187 public: | 186 public: |
| 188 explicit PanelCalloutWidget(wm::WmWindow* container) : background_(nullptr) { | 187 explicit PanelCalloutWidget(wm::WmWindow* container) : background_(nullptr) { |
| 189 InitWidget(container); | 188 InitWidget(container); |
| 190 } | 189 } |
| 191 | 190 |
| 192 void SetAlignment(ShelfAlignment alignment) { | 191 void SetAlignment(wm::ShelfAlignment alignment) { |
| 193 gfx::Rect callout_bounds = GetWindowBoundsInScreen(); | 192 gfx::Rect callout_bounds = GetWindowBoundsInScreen(); |
| 194 if (IsHorizontalAlignment(alignment)) { | 193 if (IsHorizontalAlignment(alignment)) { |
| 195 callout_bounds.set_width(kArrowWidth); | 194 callout_bounds.set_width(kArrowWidth); |
| 196 callout_bounds.set_height(kArrowHeight); | 195 callout_bounds.set_height(kArrowHeight); |
| 197 } else { | 196 } else { |
| 198 callout_bounds.set_width(kArrowHeight); | 197 callout_bounds.set_width(kArrowHeight); |
| 199 callout_bounds.set_height(kArrowWidth); | 198 callout_bounds.set_height(kArrowWidth); |
| 200 } | 199 } |
| 201 SetBounds(callout_bounds); | 200 SetBounds(callout_bounds); |
| 202 if (background_->alignment() != alignment) { | 201 if (background_->alignment() != alignment) { |
| (...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 606 // they actually become visible. | 605 // they actually become visible. |
| 607 WindowSelectorController* window_selector_controller = | 606 WindowSelectorController* window_selector_controller = |
| 608 Shell::GetInstance()->window_selector_controller(); | 607 Shell::GetInstance()->window_selector_controller(); |
| 609 if (in_layout_ || !window_selector_controller || | 608 if (in_layout_ || !window_selector_controller || |
| 610 (window_selector_controller->IsSelecting() && | 609 (window_selector_controller->IsSelecting() && |
| 611 !window_selector_controller->IsRestoringMinimizedWindows())) | 610 !window_selector_controller->IsRestoringMinimizedWindows())) |
| 612 return; | 611 return; |
| 613 | 612 |
| 614 base::AutoReset<bool> auto_reset_in_layout(&in_layout_, true); | 613 base::AutoReset<bool> auto_reset_in_layout(&in_layout_, true); |
| 615 | 614 |
| 616 const ShelfAlignment alignment = shelf_->alignment(); | 615 const wm::ShelfAlignment alignment = shelf_->alignment(); |
| 617 const bool horizontal = shelf_->IsHorizontalAlignment(); | 616 const bool horizontal = shelf_->IsHorizontalAlignment(); |
| 618 gfx::Rect shelf_bounds = panel_container_->ConvertRectFromScreen( | 617 gfx::Rect shelf_bounds = panel_container_->ConvertRectFromScreen( |
| 619 shelf_->shelf_widget()->GetWindowBoundsInScreen()); | 618 shelf_->shelf_widget()->GetWindowBoundsInScreen()); |
| 620 int panel_start_bounds = kPanelIdealSpacing; | 619 int panel_start_bounds = kPanelIdealSpacing; |
| 621 int panel_end_bounds = | 620 int panel_end_bounds = |
| 622 horizontal ? panel_container_->GetBounds().width() - kPanelIdealSpacing | 621 horizontal ? panel_container_->GetBounds().width() - kPanelIdealSpacing |
| 623 : panel_container_->GetBounds().height() - kPanelIdealSpacing; | 622 : panel_container_->GetBounds().height() - kPanelIdealSpacing; |
| 624 wm::WmWindow* active_panel = nullptr; | 623 wm::WmWindow* active_panel = nullptr; |
| 625 std::vector<VisiblePanelPositionInfo> visible_panels; | 624 std::vector<VisiblePanelPositionInfo> visible_panels; |
| 626 for (PanelList::iterator iter = panel_windows_.begin(); | 625 for (PanelList::iterator iter = panel_windows_.begin(); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 699 } | 698 } |
| 700 } | 699 } |
| 701 FanOutPanels(visible_panels.begin() + first_overlapping_panel, | 700 FanOutPanels(visible_panels.begin() + first_overlapping_panel, |
| 702 visible_panels.end()); | 701 visible_panels.end()); |
| 703 | 702 |
| 704 for (size_t i = 0; i < visible_panels.size(); ++i) { | 703 for (size_t i = 0; i < visible_panels.size(); ++i) { |
| 705 if (visible_panels[i].window == dragged_panel_) | 704 if (visible_panels[i].window == dragged_panel_) |
| 706 continue; | 705 continue; |
| 707 bool slide_in = visible_panels[i].slide_in; | 706 bool slide_in = visible_panels[i].slide_in; |
| 708 gfx::Rect bounds = visible_panels[i].window->GetTargetBounds(); | 707 gfx::Rect bounds = visible_panels[i].window->GetTargetBounds(); |
| 709 if (alignment == SHELF_ALIGNMENT_LEFT) | 708 if (alignment == wm::SHELF_ALIGNMENT_LEFT) |
| 710 bounds.set_x(shelf_bounds.right()); | 709 bounds.set_x(shelf_bounds.right()); |
| 711 else if (alignment == SHELF_ALIGNMENT_RIGHT) | 710 else if (alignment == wm::SHELF_ALIGNMENT_RIGHT) |
| 712 bounds.set_x(shelf_bounds.x() - bounds.width()); | 711 bounds.set_x(shelf_bounds.x() - bounds.width()); |
| 713 else | 712 else |
| 714 bounds.set_y(shelf_bounds.y() - bounds.height()); | 713 bounds.set_y(shelf_bounds.y() - bounds.height()); |
| 715 bool on_shelf = visible_panels[i].window->GetTargetBounds() == bounds; | 714 bool on_shelf = visible_panels[i].window->GetTargetBounds() == bounds; |
| 716 | 715 |
| 717 if (horizontal) { | 716 if (horizontal) { |
| 718 bounds.set_x(visible_panels[i].major_pos - | 717 bounds.set_x(visible_panels[i].major_pos - |
| 719 visible_panels[i].major_length / 2); | 718 visible_panels[i].major_length / 2); |
| 720 } else { | 719 } else { |
| 721 bounds.set_y(visible_panels[i].major_pos - | 720 bounds.set_y(visible_panels[i].major_pos - |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 838 current_bounds.x() - callout_bounds.x(), | 837 current_bounds.x() - callout_bounds.x(), |
| 839 callout_bounds.right() - current_bounds.right()); | 838 callout_bounds.right() - current_bounds.right()); |
| 840 } else { | 839 } else { |
| 841 callout_bounds.set_y( | 840 callout_bounds.set_y( |
| 842 icon_bounds.y() + (icon_bounds.height() - | 841 icon_bounds.y() + (icon_bounds.height() - |
| 843 callout_bounds.height()) / 2); | 842 callout_bounds.height()) / 2); |
| 844 distance_until_over_panel = std::max( | 843 distance_until_over_panel = std::max( |
| 845 current_bounds.y() - callout_bounds.y(), | 844 current_bounds.y() - callout_bounds.y(), |
| 846 callout_bounds.bottom() - current_bounds.bottom()); | 845 callout_bounds.bottom() - current_bounds.bottom()); |
| 847 } | 846 } |
| 848 if (shelf_->alignment() == SHELF_ALIGNMENT_LEFT) | 847 if (shelf_->alignment() == wm::SHELF_ALIGNMENT_LEFT) |
| 849 callout_bounds.set_x(bounds.x() - callout_bounds.width()); | 848 callout_bounds.set_x(bounds.x() - callout_bounds.width()); |
| 850 else if (shelf_->alignment() == SHELF_ALIGNMENT_RIGHT) | 849 else if (shelf_->alignment() == wm::SHELF_ALIGNMENT_RIGHT) |
| 851 callout_bounds.set_x(bounds.right()); | 850 callout_bounds.set_x(bounds.right()); |
| 852 else | 851 else |
| 853 callout_bounds.set_y(bounds.bottom()); | 852 callout_bounds.set_y(bounds.bottom()); |
| 854 callout_bounds = callout_widget_window->GetParent()->ConvertRectFromScreen( | 853 callout_bounds = callout_widget_window->GetParent()->ConvertRectFromScreen( |
| 855 callout_bounds); | 854 callout_bounds); |
| 856 | 855 |
| 857 callout_widget_window->SetBoundsDirect(callout_bounds); | 856 callout_widget_window->SetBoundsDirect(callout_bounds); |
| 858 panel_container_->StackChildAbove(callout_widget_window, panel); | 857 panel_container_->StackChildAbove(callout_widget_window, panel); |
| 859 | 858 |
| 860 ui::Layer* layer = callout_widget_window->GetLayer(); | 859 ui::Layer* layer = callout_widget_window->GetLayer(); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 919 // Keyboard hidden, restore original bounds if they exist. | 918 // Keyboard hidden, restore original bounds if they exist. |
| 920 panel->SetBoundsDirect(panel_state->GetRestoreBoundsInScreen()); | 919 panel->SetBoundsDirect(panel_state->GetRestoreBoundsInScreen()); |
| 921 } | 920 } |
| 922 } | 921 } |
| 923 // This bounds change will have caused a change to the Shelf which does not | 922 // This bounds change will have caused a change to the Shelf which does not |
| 924 // propogate automatically to this class, so manually recalculate bounds. | 923 // propogate automatically to this class, so manually recalculate bounds. |
| 925 OnWindowResized(); | 924 OnWindowResized(); |
| 926 } | 925 } |
| 927 | 926 |
| 928 } // namespace ash | 927 } // namespace ash |
| OLD | NEW |