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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
|
// Copyright (c) 2011 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 "ui/aura_shell/app_list.h"
#include "base/bind.h"
#include "ui/aura/event.h"
#include "ui/aura/window.h"
#include "ui/aura_shell/shell.h"
#include "ui/aura_shell/shell_delegate.h"
#include "ui/aura_shell/shell_window_ids.h"
#include "ui/gfx/screen.h"
namespace aura_shell {
namespace internal {
namespace {
// Gets preferred bounds of app list window in show/hide state.
gfx::Rect GetPreferredBounds(bool show) {
// The y-axis offset used at the beginning of showing animation.
static const int kMoveUpAnimationOffset = 50;
gfx::Point cursor = gfx::Screen::GetCursorScreenPoint();
gfx::Rect work_area = gfx::Screen::GetMonitorWorkAreaNearestPoint(cursor);
gfx::Rect widget_bounds(work_area);
widget_bounds.Inset(150, 100);
if (!show)
widget_bounds.Offset(0, kMoveUpAnimationOffset);
return widget_bounds;
}
ui::Layer* GetLayer(views::Widget* widget) {
return widget->GetNativeView()->layer();
}
} // namespace
////////////////////////////////////////////////////////////////////////////////
// AppList, public:
AppList::AppList()
: aura::EventFilter(NULL),
is_visible_(false),
widget_(NULL),
ALLOW_THIS_IN_INITIALIZER_LIST(set_widget_factory_(this)) {
}
AppList::~AppList() {
ResetWidget();
}
void AppList::SetVisible(bool visible) {
if (visible == is_visible_)
return;
is_visible_ = visible;
if (widget_) {
ScheduleAnimation();
} else if (is_visible_ && !set_widget_factory_.HasWeakPtrs()) {
Shell::GetInstance()->delegate()->RequestAppListWidget(
GetPreferredBounds(false),
base::Bind(&AppList::SetWidget, set_widget_factory_.GetWeakPtr()));
}
}
bool AppList::IsVisible() {
return widget_ && widget_->IsVisible();
}
////////////////////////////////////////////////////////////////////////////////
// AppList, private:
void AppList::SetWidget(views::Widget* widget) {
DCHECK(widget_ == NULL);
set_widget_factory_.InvalidateWeakPtrs();
if (is_visible_) {
widget_ = widget;
widget_->AddObserver(this);
GetLayer(widget_)->GetAnimator()->AddObserver(this);
Shell::GetInstance()->AddDesktopEventFilter(this);
widget_->SetBounds(GetPreferredBounds(false));
widget_->SetOpacity(0);
ScheduleAnimation();
widget_->Show();
} else {
widget->Close();
}
}
void AppList::ResetWidget() {
if (!widget_)
return;
widget_->RemoveObserver(this);
GetLayer(widget_)->GetAnimator()->RemoveObserver(this);
Shell::GetInstance()->RemoveDesktopEventFilter(this);
widget_ = NULL;
}
void AppList::ScheduleAnimation() {
ui::Layer* layer = GetLayer(widget_);
ui::LayerAnimator::ScopedSettings app_list_animation(layer->GetAnimator());
layer->SetBounds(GetPreferredBounds(is_visible_));
layer->SetOpacity(is_visible_ ? 1.0 : 0.0);
ui::Layer* default_container_layer = Shell::GetInstance()->GetContainer(
internal::kShellWindowId_DefaultContainer)->layer();
ui::LayerAnimator::ScopedSettings default_container_animation(
default_container_layer->GetAnimator());
default_container_layer->SetOpacity(is_visible_ ? 0.0 : 1.0);
}
////////////////////////////////////////////////////////////////////////////////
// AppList, aura::EventFilter implementation:
bool AppList::PreHandleKeyEvent(aura::Window* target,
aura::KeyEvent* event) {
return false;
}
bool AppList::PreHandleMouseEvent(aura::Window* target,
aura::MouseEvent* event) {
if (widget_ && is_visible_ && event->type() == ui::ET_MOUSE_PRESSED) {
aura::MouseEvent translated(*event, target, widget_->GetNativeView());
if (!widget_->GetNativeView()->ContainsPoint(translated.location()))
SetVisible(false);
}
return false;
}
ui::TouchStatus AppList::PreHandleTouchEvent(aura::Window* target,
aura::TouchEvent* event) {
return ui::TOUCH_STATUS_UNKNOWN;
}
////////////////////////////////////////////////////////////////////////////////
// AppList, ui::LayerAnimationObserver implementation:
void AppList::OnLayerAnimationEnded(
const ui::LayerAnimationSequence* sequence) {
if (!is_visible_ )
widget_->Close();
}
void AppList::OnLayerAnimationAborted(
const ui::LayerAnimationSequence* sequence) {
}
void AppList::OnLayerAnimationScheduled(
const ui::LayerAnimationSequence* sequence) {
}
////////////////////////////////////////////////////////////////////////////////
// AppList, views::Widget::Observer implementation:
void AppList::OnWidgetClosing(views::Widget* widget) {
DCHECK(widget_ == widget);
if (is_visible_)
SetVisible(false);
ResetWidget();
}
void AppList::OnWidgetActivationChanged(views::Widget* widget, bool active) {
DCHECK(widget_ == widget);
if (widget_ && is_visible_ && !active)
SetVisible(false);
}
} // namespace internal
} // namespace aura_shell
|