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.h" | 5 #include "ash/shelf/overflow_bubble.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "ash/launcher/launcher_types.h" | 9 #include "ash/launcher/launcher_types.h" |
10 #include "ash/launcher/launcher_view.h" | 10 #include "ash/launcher/launcher_view.h" |
11 #include "ash/root_window_controller.h" | 11 #include "ash/root_window_controller.h" |
12 #include "ash/shelf/shelf_layout_manager.h" | 12 #include "ash/shelf/shelf_layout_manager.h" |
13 #include "ash/shelf/shelf_widget.h" | 13 #include "ash/shelf/shelf_widget.h" |
14 #include "ash/shell.h" | 14 #include "ash/shell.h" |
15 #include "ash/system/tray/system_tray.h" | 15 #include "ash/system/tray/system_tray.h" |
16 #include "ui/aura/root_window.h" | 16 #include "ui/aura/root_window.h" |
| 17 #include "ui/base/events/event.h" |
17 #include "ui/gfx/insets.h" | 18 #include "ui/gfx/insets.h" |
18 #include "ui/gfx/screen.h" | 19 #include "ui/gfx/screen.h" |
19 #include "ui/views/bubble/bubble_delegate.h" | 20 #include "ui/views/bubble/bubble_delegate.h" |
20 #include "ui/views/bubble/bubble_frame_view.h" | 21 #include "ui/views/bubble/bubble_frame_view.h" |
21 #include "ui/views/widget/widget.h" | 22 #include "ui/views/widget/widget.h" |
22 | 23 |
23 namespace ash { | 24 namespace ash { |
24 namespace internal { | 25 namespace internal { |
25 | 26 |
26 namespace { | 27 namespace { |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 void OverflowBubbleView::InitOverflowBubble(views::View* anchor, | 100 void OverflowBubbleView::InitOverflowBubble(views::View* anchor, |
100 LauncherView* launcher_view) { | 101 LauncherView* launcher_view) { |
101 // set_anchor_view needs to be called before GetShelfLayoutManagerForLauncher | 102 // set_anchor_view needs to be called before GetShelfLayoutManagerForLauncher |
102 // can be called. | 103 // can be called. |
103 set_anchor_view(anchor); | 104 set_anchor_view(anchor); |
104 set_arrow(GetBubbleArrow()); | 105 set_arrow(GetBubbleArrow()); |
105 set_background(NULL); | 106 set_background(NULL); |
106 set_color(SkColorSetARGB(kLauncherBackgroundAlpha, 0, 0, 0)); | 107 set_color(SkColorSetARGB(kLauncherBackgroundAlpha, 0, 0, 0)); |
107 set_margins(gfx::Insets(kPadding, kPadding, kPadding, kPadding)); | 108 set_margins(gfx::Insets(kPadding, kPadding, kPadding, kPadding)); |
108 set_move_with_anchor(true); | 109 set_move_with_anchor(true); |
| 110 // Overflow bubble should not get focus. If it get focus when it is shown, |
| 111 // active state item is changed to running state. |
| 112 set_use_focusless(true); |
109 | 113 |
110 // Makes bubble view has a layer and clip its children layers. | 114 // Makes bubble view has a layer and clip its children layers. |
111 SetPaintToLayer(true); | 115 SetPaintToLayer(true); |
112 SetFillsBoundsOpaquely(false); | 116 SetFillsBoundsOpaquely(false); |
113 layer()->SetMasksToBounds(true); | 117 layer()->SetMasksToBounds(true); |
114 | 118 |
115 launcher_view_ = launcher_view; | 119 launcher_view_ = launcher_view; |
116 AddChildView(launcher_view_); | 120 AddChildView(launcher_view_); |
117 | 121 |
118 views::BubbleDelegateView::CreateBubble(this); | 122 views::BubbleDelegateView::CreateBubble(this); |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 } | 239 } |
236 | 240 |
237 GetBubbleFrameView()->SchedulePaint(); | 241 GetBubbleFrameView()->SchedulePaint(); |
238 return bubble_rect; | 242 return bubble_rect; |
239 } | 243 } |
240 | 244 |
241 } // namespace | 245 } // namespace |
242 | 246 |
243 OverflowBubble::OverflowBubble() | 247 OverflowBubble::OverflowBubble() |
244 : bubble_(NULL), | 248 : bubble_(NULL), |
| 249 anchor_(NULL), |
245 launcher_view_(NULL) { | 250 launcher_view_(NULL) { |
246 } | 251 } |
247 | 252 |
248 OverflowBubble::~OverflowBubble() { | 253 OverflowBubble::~OverflowBubble() { |
249 Hide(); | 254 Hide(); |
250 } | 255 } |
251 | 256 |
252 void OverflowBubble::Show(views::View* anchor, LauncherView* launcher_view) { | 257 void OverflowBubble::Show(views::View* anchor, LauncherView* launcher_view) { |
253 Hide(); | 258 Hide(); |
254 | 259 |
255 OverflowBubbleView* bubble_view = new OverflowBubbleView(); | 260 OverflowBubbleView* bubble_view = new OverflowBubbleView(); |
256 bubble_view->InitOverflowBubble(anchor, launcher_view); | 261 bubble_view->InitOverflowBubble(anchor, launcher_view); |
257 launcher_view_ = launcher_view; | 262 launcher_view_ = launcher_view; |
| 263 anchor_ = anchor; |
| 264 |
| 265 Shell::GetInstance()->AddPreTargetHandler(this); |
258 | 266 |
259 bubble_ = bubble_view; | 267 bubble_ = bubble_view; |
260 RootWindowController::ForWindow(anchor->GetWidget()->GetNativeView())-> | 268 RootWindowController::ForWindow(anchor->GetWidget()->GetNativeView())-> |
261 GetSystemTray()->InitializeBubbleAnimations(bubble_->GetWidget()); | 269 GetSystemTray()->InitializeBubbleAnimations(bubble_->GetWidget()); |
262 bubble_->GetWidget()->AddObserver(this); | 270 bubble_->GetWidget()->AddObserver(this); |
263 bubble_->GetWidget()->Show(); | 271 bubble_->GetWidget()->Show(); |
264 } | 272 } |
265 | 273 |
266 void OverflowBubble::Hide() { | 274 void OverflowBubble::Hide() { |
267 if (!IsShowing()) | 275 if (!IsShowing()) |
268 return; | 276 return; |
269 | 277 |
| 278 Shell::GetInstance()->RemovePreTargetHandler(this); |
270 bubble_->GetWidget()->RemoveObserver(this); | 279 bubble_->GetWidget()->RemoveObserver(this); |
271 bubble_->GetWidget()->Close(); | 280 bubble_->GetWidget()->Close(); |
272 bubble_ = NULL; | 281 bubble_ = NULL; |
| 282 anchor_ = NULL; |
273 launcher_view_ = NULL; | 283 launcher_view_ = NULL; |
274 } | 284 } |
275 | 285 |
| 286 void OverflowBubble::OnMouseEvent(ui::MouseEvent* event) { |
| 287 if (event->type() == ui::ET_MOUSE_PRESSED && |
| 288 !bubble_->GetBoundsInScreen().Contains(event->root_location()) && |
| 289 !anchor_->GetBoundsInScreen().Contains(event->root_location())) { |
| 290 Hide(); |
| 291 } |
| 292 } |
| 293 |
| 294 void OverflowBubble::OnTouchEvent(ui::TouchEvent* event) { |
| 295 if (event->type() == ui::ET_TOUCH_PRESSED && |
| 296 !bubble_->GetBoundsInScreen().Contains(event->root_location()) && |
| 297 !anchor_->GetBoundsInScreen().Contains(event->root_location())) { |
| 298 Hide(); |
| 299 } |
| 300 } |
| 301 |
276 void OverflowBubble::OnWidgetDestroying(views::Widget* widget) { | 302 void OverflowBubble::OnWidgetDestroying(views::Widget* widget) { |
277 DCHECK(widget == bubble_->GetWidget()); | 303 DCHECK(widget == bubble_->GetWidget()); |
278 bubble_ = NULL; | 304 bubble_ = NULL; |
| 305 anchor_ = NULL; |
279 launcher_view_ = NULL; | 306 launcher_view_ = NULL; |
280 ShelfLayoutManager::ForLauncher( | 307 ShelfLayoutManager::ForLauncher( |
281 widget->GetNativeView())->shelf_widget()->launcher()->SchedulePaint(); | 308 widget->GetNativeView())->shelf_widget()->launcher()->SchedulePaint(); |
282 } | 309 } |
283 | 310 |
284 } // namespace internal | 311 } // namespace internal |
285 } // namespace ash | 312 } // namespace ash |
OLD | NEW |