Chromium Code Reviews| 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_constants.h" | 10 #include "ash/shelf/shelf_constants.h" |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 34 | 34 |
| 35 OverflowBubbleView::OverflowBubbleView() | 35 OverflowBubbleView::OverflowBubbleView() |
| 36 : shelf_view_(NULL) { | 36 : shelf_view_(NULL) { |
| 37 } | 37 } |
| 38 | 38 |
| 39 OverflowBubbleView::~OverflowBubbleView() { | 39 OverflowBubbleView::~OverflowBubbleView() { |
| 40 } | 40 } |
| 41 | 41 |
| 42 void OverflowBubbleView::InitOverflowBubble(views::View* anchor, | 42 void OverflowBubbleView::InitOverflowBubble(views::View* anchor, |
| 43 ShelfView* shelf_view) { | 43 ShelfView* shelf_view) { |
| 44 // set_anchor_view needs to be called before GetShelfLayoutManager() can be | |
| 45 // called. | |
| 46 SetAnchorView(anchor); | 44 SetAnchorView(anchor); |
| 47 set_arrow(GetBubbleArrow()); | 45 set_arrow(GetBubbleArrow()); |
| 48 set_background(NULL); | 46 set_background(NULL); |
| 49 set_color(SkColorSetARGB(kShelfBackgroundAlpha, 0, 0, 0)); | 47 set_color(SkColorSetARGB(kShelfBackgroundAlpha, 0, 0, 0)); |
| 50 set_margins(gfx::Insets(kPadding, kPadding, kPadding, kPadding)); | 48 set_margins(gfx::Insets(kPadding, kPadding, kPadding, kPadding)); |
| 51 // Overflow bubble should not get focus. If it get focus when it is shown, | 49 // Overflow bubble should not get focus. If it get focus when it is shown, |
| 52 // active state item is changed to running state. | 50 // active state item is changed to running state. |
| 53 set_can_activate(false); | 51 set_can_activate(false); |
| 54 | 52 |
| 55 // Makes bubble view has a layer and clip its children layers. | 53 // Makes bubble view has a layer and clip its children layers. |
| 56 SetPaintToLayer(true); | 54 SetPaintToLayer(true); |
| 57 SetFillsBoundsOpaquely(false); | 55 SetFillsBoundsOpaquely(false); |
| 58 layer()->SetMasksToBounds(true); | 56 layer()->SetMasksToBounds(true); |
| 59 | 57 |
| 60 shelf_view_ = shelf_view; | 58 shelf_view_ = shelf_view; |
| 61 AddChildView(shelf_view_); | 59 AddChildView(shelf_view_); |
| 62 | 60 |
| 63 set_parent_window(Shell::GetContainer( | 61 set_parent_window(Shell::GetContainer( |
| 64 anchor->GetWidget()->GetNativeWindow()->GetRootWindow(), | 62 anchor->GetWidget()->GetNativeWindow()->GetRootWindow(), |
| 65 kShellWindowId_ShelfBubbleContainer)); | 63 kShellWindowId_ShelfBubbleContainer)); |
| 66 views::BubbleDelegateView::CreateBubble(this); | 64 views::BubbleDelegateView::CreateBubble(this); |
| 67 } | 65 } |
| 68 | 66 |
| 69 bool OverflowBubbleView::IsHorizontalAlignment() const { | 67 bool OverflowBubbleView::IsHorizontalAlignment() const { |
| 70 ShelfLayoutManager* shelf_layout_manager = GetShelfLayoutManager(); | 68 ShelfLayoutManager* shelf_layout_manager = |
| 69 shelf_view_ ? shelf_view_->shelf_layout_manager() : nullptr; | |
| 71 return shelf_layout_manager ? shelf_layout_manager->IsHorizontalAlignment() | 70 return shelf_layout_manager ? shelf_layout_manager->IsHorizontalAlignment() |
| 72 : false; | 71 : false; |
| 73 } | 72 } |
| 74 | 73 |
| 75 const gfx::Size OverflowBubbleView::GetContentsSize() const { | 74 const gfx::Size OverflowBubbleView::GetContentsSize() const { |
| 76 return static_cast<views::View*>(shelf_view_)->GetPreferredSize(); | 75 return static_cast<views::View*>(shelf_view_)->GetPreferredSize(); |
| 77 } | 76 } |
| 78 | 77 |
| 79 // Gets arrow location based on shelf alignment. | 78 // Gets arrow location based on shelf alignment. |
| 80 views::BubbleBorder::Arrow OverflowBubbleView::GetBubbleArrow() const { | 79 views::BubbleBorder::Arrow OverflowBubbleView::GetBubbleArrow() const { |
| 81 ShelfLayoutManager* shelf_layout_manager = GetShelfLayoutManager(); | 80 ShelfLayoutManager* shelf_layout_manager = |
|
sky
2016/02/03 00:01:42
nit: keep GetShelfLayoutManager but makes it imple
sadrul
2016/02/03 02:07:58
Done.
| |
| 81 shelf_view_ ? shelf_view_->shelf_layout_manager() : nullptr; | |
| 82 return shelf_layout_manager ? | 82 return shelf_layout_manager ? |
| 83 shelf_layout_manager->SelectValueForShelfAlignment( | 83 shelf_layout_manager->SelectValueForShelfAlignment( |
| 84 views::BubbleBorder::BOTTOM_LEFT, | 84 views::BubbleBorder::BOTTOM_LEFT, |
| 85 views::BubbleBorder::LEFT_TOP, | 85 views::BubbleBorder::LEFT_TOP, |
| 86 views::BubbleBorder::RIGHT_TOP, | 86 views::BubbleBorder::RIGHT_TOP, |
| 87 views::BubbleBorder::TOP_LEFT) : | 87 views::BubbleBorder::TOP_LEFT) : |
| 88 views::BubbleBorder::NONE; | 88 views::BubbleBorder::NONE; |
| 89 } | 89 } |
| 90 | 90 |
| 91 void OverflowBubbleView::ScrollByXOffset(int x_offset) { | 91 void OverflowBubbleView::ScrollByXOffset(int x_offset) { |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 157 // directions as in OverflowBubbleView::OnScrollEvent. | 157 // directions as in OverflowBubbleView::OnScrollEvent. |
| 158 if (IsHorizontalAlignment()) | 158 if (IsHorizontalAlignment()) |
| 159 ScrollByXOffset(-event.y_offset()); | 159 ScrollByXOffset(-event.y_offset()); |
| 160 else | 160 else |
| 161 ScrollByYOffset(-event.y_offset()); | 161 ScrollByYOffset(-event.y_offset()); |
| 162 Layout(); | 162 Layout(); |
| 163 | 163 |
| 164 return true; | 164 return true; |
| 165 } | 165 } |
| 166 | 166 |
| 167 ShelfLayoutManager* OverflowBubbleView::GetShelfLayoutManager() const { | |
| 168 return GetAnchorView() ? ShelfLayoutManager::ForShelf( | |
| 169 GetAnchorView()->GetWidget()->GetNativeView()) | |
| 170 : NULL; | |
| 171 } | |
| 172 | |
| 173 void OverflowBubbleView::OnScrollEvent(ui::ScrollEvent* event) { | 167 void OverflowBubbleView::OnScrollEvent(ui::ScrollEvent* event) { |
| 174 ScrollByXOffset(-event->x_offset()); | 168 ScrollByXOffset(-event->x_offset()); |
| 175 ScrollByYOffset(-event->y_offset()); | 169 ScrollByYOffset(-event->y_offset()); |
| 176 Layout(); | 170 Layout(); |
| 177 event->SetHandled(); | 171 event->SetHandled(); |
| 178 } | 172 } |
| 179 | 173 |
| 180 gfx::Rect OverflowBubbleView::GetBubbleBounds() { | 174 gfx::Rect OverflowBubbleView::GetBubbleBounds() { |
| 181 views::BubbleBorder* border = GetBubbleFrameView()->bubble_border(); | 175 views::BubbleBorder* border = GetBubbleFrameView()->bubble_border(); |
| 182 gfx::Insets bubble_insets = border->GetInsets(); | 176 gfx::Insets bubble_insets = border->GetInsets(); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 218 | 212 |
| 219 bubble_rect.Offset(0, offset); | 213 bubble_rect.Offset(0, offset); |
| 220 border->set_arrow_offset(anchor_rect.CenterPoint().y() - bubble_rect.y()); | 214 border->set_arrow_offset(anchor_rect.CenterPoint().y() - bubble_rect.y()); |
| 221 } | 215 } |
| 222 | 216 |
| 223 GetBubbleFrameView()->SchedulePaint(); | 217 GetBubbleFrameView()->SchedulePaint(); |
| 224 return bubble_rect; | 218 return bubble_rect; |
| 225 } | 219 } |
| 226 | 220 |
| 227 } // namespace ash | 221 } // namespace ash |
| OLD | NEW |