| 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 GetShelfLayoutManagerForShelf |
| 46 // can be called. | 46 // can be 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 = GetShelfLayoutManagerForShelf(); |
| 73 return shelf_layout_manager ? | 73 return shelf_layout_manager ? |
| 74 shelf_layout_manager->IsHorizontalAlignment() : | 74 shelf_layout_manager->IsHorizontalAlignment() : |
| 75 false; | 75 false; |
| 76 } | 76 } |
| 77 | 77 |
| 78 const gfx::Size OverflowBubbleView::GetContentsSize() const { | 78 const gfx::Size OverflowBubbleView::GetContentsSize() const { |
| 79 return static_cast<views::View*>(shelf_view_)->GetPreferredSize(); | 79 return static_cast<views::View*>(shelf_view_)->GetPreferredSize(); |
| 80 } | 80 } |
| 81 | 81 |
| 82 // Gets arrow location based on shelf alignment. | 82 // Gets arrow location based on shelf alignment. |
| 83 views::BubbleBorder::Arrow OverflowBubbleView::GetBubbleArrow() const { | 83 views::BubbleBorder::Arrow OverflowBubbleView::GetBubbleArrow() const { |
| 84 ShelfLayoutManager* shelf_layout_manager = GetShelfLayoutManagerForLauncher(); | 84 ShelfLayoutManager* shelf_layout_manager = GetShelfLayoutManagerForShelf(); |
| 85 return shelf_layout_manager ? | 85 return shelf_layout_manager ? |
| 86 shelf_layout_manager->SelectValueForShelfAlignment( | 86 shelf_layout_manager->SelectValueForShelfAlignment( |
| 87 views::BubbleBorder::BOTTOM_LEFT, | 87 views::BubbleBorder::BOTTOM_LEFT, |
| 88 views::BubbleBorder::LEFT_TOP, | 88 views::BubbleBorder::LEFT_TOP, |
| 89 views::BubbleBorder::RIGHT_TOP, | 89 views::BubbleBorder::RIGHT_TOP, |
| 90 views::BubbleBorder::TOP_LEFT) : | 90 views::BubbleBorder::TOP_LEFT) : |
| 91 views::BubbleBorder::NONE; | 91 views::BubbleBorder::NONE; |
| 92 } | 92 } |
| 93 | 93 |
| 94 void OverflowBubbleView::ScrollByXOffset(int x_offset) { | 94 void OverflowBubbleView::ScrollByXOffset(int x_offset) { |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 if (IsHorizontalAlignment()) | 159 if (IsHorizontalAlignment()) |
| 160 ScrollByXOffset(-event.y_offset()); | 160 ScrollByXOffset(-event.y_offset()); |
| 161 else | 161 else |
| 162 ScrollByYOffset(-event.y_offset()); | 162 ScrollByYOffset(-event.y_offset()); |
| 163 Layout(); | 163 Layout(); |
| 164 | 164 |
| 165 return true; | 165 return true; |
| 166 } | 166 } |
| 167 | 167 |
| 168 ShelfLayoutManager* | 168 ShelfLayoutManager* |
| 169 OverflowBubbleView::GetShelfLayoutManagerForLauncher() const { | 169 OverflowBubbleView::GetShelfLayoutManagerForShelf() const { |
| 170 return GetAnchorView() ? | 170 return GetAnchorView() ? |
| 171 ShelfLayoutManager::ForLauncher( | 171 ShelfLayoutManager::ForShelf( |
| 172 GetAnchorView()->GetWidget()->GetNativeView()) : | 172 GetAnchorView()->GetWidget()->GetNativeView()) : |
| 173 NULL; | 173 NULL; |
| 174 } | 174 } |
| 175 | 175 |
| 176 void OverflowBubbleView::OnScrollEvent(ui::ScrollEvent* event) { | 176 void OverflowBubbleView::OnScrollEvent(ui::ScrollEvent* event) { |
| 177 ScrollByXOffset(-event->x_offset()); | 177 ScrollByXOffset(-event->x_offset()); |
| 178 ScrollByYOffset(-event->y_offset()); | 178 ScrollByYOffset(-event->y_offset()); |
| 179 Layout(); | 179 Layout(); |
| 180 event->SetHandled(); | 180 event->SetHandled(); |
| 181 } | 181 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 bubble_rect.Offset(0, offset); | 220 bubble_rect.Offset(0, offset); |
| 221 border->set_arrow_offset(anchor_rect.CenterPoint().y() - bubble_rect.y()); | 221 border->set_arrow_offset(anchor_rect.CenterPoint().y() - bubble_rect.y()); |
| 222 } | 222 } |
| 223 | 223 |
| 224 GetBubbleFrameView()->SchedulePaint(); | 224 GetBubbleFrameView()->SchedulePaint(); |
| 225 return bubble_rect; | 225 return bubble_rect; |
| 226 } | 226 } |
| 227 | 227 |
| 228 } // namespace internal | 228 } // namespace internal |
| 229 } // namespace ash | 229 } // namespace ash |
| OLD | NEW |