blob: 35c885f338c5a1ef4f536fb1b182cd53bb16ee14 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/shelf/overflow_bubble.h"
#include "ash/root_window_controller.h"
#include "ash/shelf/overflow_bubble_view.h"
#include "ash/shelf/shelf_layout_manager.h"
#include "ash/shelf/shelf_view.h"
#include "ash/shelf/shelf_widget.h"
#include "ash/shell.h"
#include "ash/system/tray/system_tray.h"
#include "ui/aura/client/screen_position_client.h"
#include "ui/aura/root_window.h"
#include "ui/events/event.h"
#include "ui/gfx/screen.h"
#include "ui/views/widget/widget.h"
namespace ash {
namespace internal {
OverflowBubble::OverflowBubble()
: bubble_(NULL),
anchor_(NULL),
shelf_view_(NULL) {
}
OverflowBubble::~OverflowBubble() {
Hide();
}
void OverflowBubble::Show(views::View* anchor, ShelfView* shelf_view) {
Hide();
bubble_ = new OverflowBubbleView();
bubble_->InitOverflowBubble(anchor, shelf_view);
shelf_view_ = shelf_view;
anchor_ = anchor;
Shell::GetInstance()->AddPreTargetHandler(this);
RootWindowController::ForWindow(anchor->GetWidget()->GetNativeView())->
GetSystemTray()->InitializeBubbleAnimations(bubble_->GetWidget());
bubble_->GetWidget()->AddObserver(this);
bubble_->GetWidget()->Show();
}
void OverflowBubble::Hide() {
if (!IsShowing())
return;
Shell::GetInstance()->RemovePreTargetHandler(this);
bubble_->GetWidget()->RemoveObserver(this);
bubble_->GetWidget()->Close();
bubble_ = NULL;
anchor_ = NULL;
shelf_view_ = NULL;
}
void OverflowBubble::HideBubbleAndRefreshButton() {
if (!IsShowing())
return;
views::View* anchor = anchor_;
Hide();
// Update overflow button (|anchor|) status when overflow bubble is hidden
// by outside event of overflow button.
anchor->SchedulePaint();
}
void OverflowBubble::ProcessPressedEvent(ui::LocatedEvent* event) {
aura::Window* target = static_cast<aura::Window*>(event->target());
gfx::Point event_location_in_screen = event->location();
aura::client::GetScreenPositionClient(target->GetRootWindow())->
ConvertPointToScreen(target, &event_location_in_screen);
if (!shelf_view_->IsShowingMenu() &&
!bubble_->GetBoundsInScreen().Contains(event_location_in_screen) &&
!anchor_->GetBoundsInScreen().Contains(event_location_in_screen)) {
HideBubbleAndRefreshButton();
}
}
void OverflowBubble::OnMouseEvent(ui::MouseEvent* event) {
if (event->type() == ui::ET_MOUSE_PRESSED)
ProcessPressedEvent(event);
}
void OverflowBubble::OnTouchEvent(ui::TouchEvent* event) {
if (event->type() == ui::ET_TOUCH_PRESSED)
ProcessPressedEvent(event);
}
void OverflowBubble::OnWidgetDestroying(views::Widget* widget) {
DCHECK(widget == bubble_->GetWidget());
bubble_ = NULL;
anchor_ = NULL;
shelf_view_ = NULL;
ShelfLayoutManager::ForLauncher(
widget->GetNativeView())->shelf_widget()->launcher()->SchedulePaint();
}
} // namespace internal
} // namespace ash
|