| 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/shelf/overflow_bubble_view.h" | 5 #include "ash/shelf/overflow_bubble_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "ash/root_window_controller.h" | 9 #include "ash/root_window_controller.h" |
| 10 #include "ash/shelf/shelf.h" |
| 10 #include "ash/shelf/shelf_constants.h" | 11 #include "ash/shelf/shelf_constants.h" |
| 11 #include "ash/shelf/shelf_layout_manager.h" | |
| 12 #include "ash/shelf/shelf_view.h" | 12 #include "ash/shelf/shelf_view.h" |
| 13 #include "ash/shell.h" | 13 #include "ash/shell.h" |
| 14 #include "ash/shell_window_ids.h" | 14 #include "ash/shell_window_ids.h" |
| 15 #include "ui/events/event.h" | 15 #include "ui/events/event.h" |
| 16 #include "ui/gfx/geometry/insets.h" | 16 #include "ui/gfx/geometry/insets.h" |
| 17 #include "ui/gfx/screen.h" | 17 #include "ui/gfx/screen.h" |
| 18 #include "ui/views/bubble/bubble_frame_view.h" | 18 #include "ui/views/bubble/bubble_frame_view.h" |
| 19 #include "ui/views/widget/widget.h" | 19 #include "ui/views/widget/widget.h" |
| 20 | 20 |
| 21 namespace ash { | 21 namespace ash { |
| 22 namespace { | 22 namespace { |
| 23 | 23 |
| 24 // Max bubble size to screen size ratio. | 24 // Max bubble size to screen size ratio. |
| 25 const float kMaxBubbleSizeToScreenRatio = 0.5f; | 25 const float kMaxBubbleSizeToScreenRatio = 0.5f; |
| 26 | 26 |
| 27 // Inner padding in pixels for shelf view inside bubble. | 27 // Inner padding in pixels for shelf view inside bubble. |
| 28 const int kPadding = 2; | 28 const int kPadding = 2; |
| 29 | 29 |
| 30 // Padding space in pixels between ShelfView's left/top edge to its contents. | 30 // Padding space in pixels between ShelfView's left/top edge to its contents. |
| 31 const int kShelfViewLeadingInset = 8; | 31 const int kShelfViewLeadingInset = 8; |
| 32 | 32 |
| 33 } // namespace | 33 } // namespace |
| 34 | 34 |
| 35 OverflowBubbleView::OverflowBubbleView() | 35 OverflowBubbleView::OverflowBubbleView() : shelf_view_(NULL) {} |
| 36 : shelf_view_(NULL) { | |
| 37 } | |
| 38 | 36 |
| 39 OverflowBubbleView::~OverflowBubbleView() { | 37 OverflowBubbleView::~OverflowBubbleView() {} |
| 40 } | |
| 41 | 38 |
| 42 void OverflowBubbleView::InitOverflowBubble(views::View* anchor, | 39 void OverflowBubbleView::InitOverflowBubble(views::View* anchor, |
| 43 ShelfView* shelf_view) { | 40 ShelfView* shelf_view) { |
| 44 SetAnchorView(anchor); | 41 SetAnchorView(anchor); |
| 45 set_arrow(GetBubbleArrow()); | 42 set_arrow(GetBubbleArrow()); |
| 46 set_background(NULL); | 43 set_background(NULL); |
| 47 set_color(SkColorSetARGB(kShelfBackgroundAlpha, 0, 0, 0)); | 44 set_color(SkColorSetARGB(kShelfBackgroundAlpha, 0, 0, 0)); |
| 48 set_margins(gfx::Insets(kPadding, kPadding, kPadding, kPadding)); | 45 set_margins(gfx::Insets(kPadding, kPadding, kPadding, kPadding)); |
| 49 // Overflow bubble should not get focus. If it get focus when it is shown, | 46 // Overflow bubble should not get focus. If it get focus when it is shown, |
| 50 // active state item is changed to running state. | 47 // active state item is changed to running state. |
| 51 set_can_activate(false); | 48 set_can_activate(false); |
| 52 | 49 |
| 53 // Makes bubble view has a layer and clip its children layers. | 50 // Makes bubble view has a layer and clip its children layers. |
| 54 SetPaintToLayer(true); | 51 SetPaintToLayer(true); |
| 55 SetFillsBoundsOpaquely(false); | 52 SetFillsBoundsOpaquely(false); |
| 56 layer()->SetMasksToBounds(true); | 53 layer()->SetMasksToBounds(true); |
| 57 | 54 |
| 58 shelf_view_ = shelf_view; | 55 shelf_view_ = shelf_view; |
| 59 AddChildView(shelf_view_); | 56 AddChildView(shelf_view_); |
| 60 | 57 |
| 61 set_parent_window(Shell::GetContainer( | 58 set_parent_window(Shell::GetContainer( |
| 62 anchor->GetWidget()->GetNativeWindow()->GetRootWindow(), | 59 anchor->GetWidget()->GetNativeWindow()->GetRootWindow(), |
| 63 kShellWindowId_ShelfBubbleContainer)); | 60 kShellWindowId_ShelfBubbleContainer)); |
| 64 views::BubbleDelegateView::CreateBubble(this); | 61 views::BubbleDelegateView::CreateBubble(this); |
| 65 } | 62 } |
| 66 | 63 |
| 67 bool OverflowBubbleView::IsHorizontalAlignment() const { | 64 bool OverflowBubbleView::IsHorizontalAlignment() const { |
| 68 ShelfLayoutManager* shelf_layout_manager = GetShelfLayoutManager(); | 65 return shelf_view_ ? shelf_view_->shelf()->IsHorizontalAlignment() : false; |
| 69 return shelf_layout_manager ? shelf_layout_manager->IsHorizontalAlignment() | |
| 70 : false; | |
| 71 } | 66 } |
| 72 | 67 |
| 73 const gfx::Size OverflowBubbleView::GetContentsSize() const { | 68 const gfx::Size OverflowBubbleView::GetContentsSize() const { |
| 74 return static_cast<views::View*>(shelf_view_)->GetPreferredSize(); | 69 return static_cast<views::View*>(shelf_view_)->GetPreferredSize(); |
| 75 } | 70 } |
| 76 | 71 |
| 77 // Gets arrow location based on shelf alignment. | 72 // Gets arrow location based on shelf alignment. |
| 78 views::BubbleBorder::Arrow OverflowBubbleView::GetBubbleArrow() const { | 73 views::BubbleBorder::Arrow OverflowBubbleView::GetBubbleArrow() const { |
| 79 ShelfLayoutManager* shelf_layout_manager = GetShelfLayoutManager(); | 74 if (!shelf_view_) |
| 80 return shelf_layout_manager ? | 75 return views::BubbleBorder::NONE; |
| 81 shelf_layout_manager->SelectValueForShelfAlignment( | 76 return shelf_view_->shelf()->SelectValueForShelfAlignment( |
| 82 views::BubbleBorder::BOTTOM_LEFT, | 77 views::BubbleBorder::BOTTOM_LEFT, views::BubbleBorder::LEFT_TOP, |
| 83 views::BubbleBorder::LEFT_TOP, | 78 views::BubbleBorder::RIGHT_TOP, views::BubbleBorder::TOP_LEFT); |
| 84 views::BubbleBorder::RIGHT_TOP, | |
| 85 views::BubbleBorder::TOP_LEFT) : | |
| 86 views::BubbleBorder::NONE; | |
| 87 } | 79 } |
| 88 | 80 |
| 89 void OverflowBubbleView::ScrollByXOffset(int x_offset) { | 81 void OverflowBubbleView::ScrollByXOffset(int x_offset) { |
| 90 const gfx::Rect visible_bounds(GetContentsBounds()); | 82 const gfx::Rect visible_bounds(GetContentsBounds()); |
| 91 const gfx::Size contents_size(GetContentsSize()); | 83 const gfx::Size contents_size(GetContentsSize()); |
| 92 | 84 |
| 93 DCHECK_GE(contents_size.width(), visible_bounds.width()); | 85 DCHECK_GE(contents_size.width(), visible_bounds.width()); |
| 94 int x = std::min(contents_size.width() - visible_bounds.width(), | 86 int x = std::min(contents_size.width() - visible_bounds.width(), |
| 95 std::max(0, scroll_offset_.x() + x_offset)); | 87 std::max(0, scroll_offset_.x() + x_offset)); |
| 96 scroll_offset_.set_x(x); | 88 scroll_offset_.set_x(x); |
| 97 } | 89 } |
| 98 | 90 |
| 99 void OverflowBubbleView::ScrollByYOffset(int y_offset) { | 91 void OverflowBubbleView::ScrollByYOffset(int y_offset) { |
| 100 const gfx::Rect visible_bounds(GetContentsBounds()); | 92 const gfx::Rect visible_bounds(GetContentsBounds()); |
| 101 const gfx::Size contents_size(GetContentsSize()); | 93 const gfx::Size contents_size(GetContentsSize()); |
| 102 | 94 |
| 103 DCHECK_GE(contents_size.width(), visible_bounds.width()); | 95 DCHECK_GE(contents_size.width(), visible_bounds.width()); |
| 104 int y = std::min(contents_size.height() - visible_bounds.height(), | 96 int y = std::min(contents_size.height() - visible_bounds.height(), |
| 105 std::max(0, scroll_offset_.y() + y_offset)); | 97 std::max(0, scroll_offset_.y() + y_offset)); |
| 106 scroll_offset_.set_y(y); | 98 scroll_offset_.set_y(y); |
| 107 } | 99 } |
| 108 | 100 |
| 109 ShelfLayoutManager* OverflowBubbleView::GetShelfLayoutManager() const { | |
| 110 return shelf_view_ ? shelf_view_->shelf_layout_manager() : nullptr; | |
| 111 } | |
| 112 | |
| 113 gfx::Size OverflowBubbleView::GetPreferredSize() const { | 101 gfx::Size OverflowBubbleView::GetPreferredSize() const { |
| 114 gfx::Size preferred_size = GetContentsSize(); | 102 gfx::Size preferred_size = GetContentsSize(); |
| 115 | 103 |
| 116 const gfx::Rect monitor_rect = | 104 const gfx::Rect monitor_rect = |
| 117 gfx::Screen::GetScreen() | 105 gfx::Screen::GetScreen() |
| 118 ->GetDisplayNearestPoint(GetAnchorRect().CenterPoint()) | 106 ->GetDisplayNearestPoint(GetAnchorRect().CenterPoint()) |
| 119 .work_area(); | 107 .work_area(); |
| 120 if (!monitor_rect.IsEmpty()) { | 108 if (!monitor_rect.IsEmpty()) { |
| 121 if (IsHorizontalAlignment()) { | 109 if (IsHorizontalAlignment()) { |
| 122 preferred_size.set_width(std::min( | 110 preferred_size.set_width(std::min( |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 | 202 |
| 215 bubble_rect.Offset(0, offset); | 203 bubble_rect.Offset(0, offset); |
| 216 border->set_arrow_offset(anchor_rect.CenterPoint().y() - bubble_rect.y()); | 204 border->set_arrow_offset(anchor_rect.CenterPoint().y() - bubble_rect.y()); |
| 217 } | 205 } |
| 218 | 206 |
| 219 GetBubbleFrameView()->SchedulePaint(); | 207 GetBubbleFrameView()->SchedulePaint(); |
| 220 return bubble_rect; | 208 return bubble_rect; |
| 221 } | 209 } |
| 222 | 210 |
| 223 } // namespace ash | 211 } // namespace ash |
| OLD | NEW |