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