Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(245)

Side by Side Diff: ash/wm/overview/window_selector_item.cc

Issue 872113004: Modified OverviewMode's LabelButton bounds to cover the entire item. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed nits Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ash/wm/overview/window_selector_item.h ('k') | ash/wm/overview/window_selector_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/wm/overview/window_selector_item.h" 5 #include "ash/wm/overview/window_selector_item.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "ash/screen_util.h" 10 #include "ash/screen_util.h"
11 #include "ash/shell.h" 11 #include "ash/shell.h"
12 #include "ash/shell_window_ids.h" 12 #include "ash/shell_window_ids.h"
13 #include "ash/wm/overview/overview_animation_type.h" 13 #include "ash/wm/overview/overview_animation_type.h"
14 #include "ash/wm/overview/overview_window_button.h"
15 #include "ash/wm/overview/scoped_overview_animation_settings.h" 14 #include "ash/wm/overview/scoped_overview_animation_settings.h"
16 #include "ash/wm/overview/scoped_transform_overview_window.h" 15 #include "ash/wm/overview/scoped_transform_overview_window.h"
17 #include "ash/wm/overview/window_selector_controller.h" 16 #include "ash/wm/overview/window_selector_controller.h"
17 #include "ash/wm/window_state.h"
18 #include "base/auto_reset.h" 18 #include "base/auto_reset.h"
19 #include "base/strings/string_util.h" 19 #include "base/strings/string_util.h"
20 #include "base/strings/utf_string_conversions.h" 20 #include "base/strings/utf_string_conversions.h"
21 #include "base/time/time.h" 21 #include "base/time/time.h"
22 #include "grit/ash_resources.h" 22 #include "grit/ash_resources.h"
23 #include "grit/ash_strings.h" 23 #include "grit/ash_strings.h"
24 #include "ui/aura/window.h" 24 #include "ui/aura/window.h"
25 #include "ui/base/l10n/l10n_util.h" 25 #include "ui/base/l10n/l10n_util.h"
26 #include "ui/base/resource/resource_bundle.h" 26 #include "ui/base/resource/resource_bundle.h"
27 #include "ui/gfx/geometry/vector2d.h" 27 #include "ui/gfx/geometry/vector2d.h"
28 #include "ui/gfx/transform_util.h" 28 #include "ui/gfx/transform_util.h"
29 #include "ui/strings/grit/ui_strings.h" 29 #include "ui/strings/grit/ui_strings.h"
30 #include "ui/views/border.h"
30 #include "ui/views/controls/button/image_button.h" 31 #include "ui/views/controls/button/image_button.h"
31 #include "ui/views/layout/box_layout.h" 32 #include "ui/views/layout/box_layout.h"
32 #include "ui/views/widget/widget.h" 33 #include "ui/views/widget/widget.h"
33 #include "ui/wm/core/window_util.h" 34 #include "ui/wm/core/window_util.h"
34 35
35 namespace ash { 36 namespace ash {
36 37
37 namespace { 38 namespace {
38 39
39 // In the conceptual overview table, the window margin is the space reserved 40 // In the conceptual overview table, the window margin is the space reserved
40 // around the window within the cell. This margin does not overlap so the 41 // around the window within the cell. This margin does not overlap so the
41 // closest distance between adjacent windows will be twice this amount. 42 // closest distance between adjacent windows will be twice this amount.
42 static const int kWindowMargin = 30; 43 static const int kWindowMargin = 30;
43 44
45 // Foreground label color.
46 static const SkColor kLabelColor = SK_ColorWHITE;
47
48 // Label shadow color.
49 static const SkColor kLabelShadow = 0xB0000000;
50
51 // Vertical padding for the label, on top of it.
52 static const int kVerticalLabelPadding = 20;
53
54 // Solid shadow length from the label
55 static const int kVerticalShadowOffset = 1;
56
57 // Amount of blur applied to the label shadow
58 static const int kShadowBlur = 10;
59
44 // Opacity for dimmed items. 60 // Opacity for dimmed items.
45 static const float kDimmedItemOpacity = 0.5f; 61 static const float kDimmedItemOpacity = 0.5f;
46 62
47 // Calculates the |window| bounds after being transformed to the selector's 63 // Calculates the |window| bounds after being transformed to the selector's
48 // space. The returned Rect is in virtual screen coordinates. 64 // space. The returned Rect is in virtual screen coordinates.
49 gfx::Rect GetTransformedBounds(aura::Window* window) { 65 gfx::Rect GetTransformedBounds(aura::Window* window) {
50 gfx::RectF bounds(ScreenUtil::ConvertRectToScreen(window->GetRootWindow(), 66 gfx::RectF bounds(ScreenUtil::ConvertRectToScreen(window->GetRootWindow(),
51 window->layer()->GetTargetBounds())); 67 window->layer()->GetTargetBounds()));
52 gfx::Transform new_transform = TransformAboutPivot( 68 gfx::Transform new_transform = TransformAboutPivot(
53 gfx::Point(bounds.x(), bounds.y()), 69 gfx::Point(bounds.x(), bounds.y()),
(...skipping 21 matching lines...) Expand all
75 rb.GetImageSkiaNamed(IDR_AURA_WINDOW_OVERVIEW_CLOSE_H)); 91 rb.GetImageSkiaNamed(IDR_AURA_WINDOW_OVERVIEW_CLOSE_H));
76 SetImage(views::CustomButton::STATE_PRESSED, 92 SetImage(views::CustomButton::STATE_PRESSED,
77 rb.GetImageSkiaNamed(IDR_AURA_WINDOW_OVERVIEW_CLOSE_P)); 93 rb.GetImageSkiaNamed(IDR_AURA_WINDOW_OVERVIEW_CLOSE_P));
78 } 94 }
79 95
80 OverviewCloseButton::~OverviewCloseButton() { 96 OverviewCloseButton::~OverviewCloseButton() {
81 } 97 }
82 98
83 } // namespace 99 } // namespace
84 100
101 WindowSelectorItem::OverviewLabelButton::OverviewLabelButton(
102 views::ButtonListener* listener,
103 const base::string16& text)
104 : LabelButton(listener, text) {
oshima 2015/02/10 21:43:16 you need to initialize top_padding_ here.
105 }
106
107 WindowSelectorItem::OverviewLabelButton::~OverviewLabelButton() {
108 }
109
110 gfx::Rect WindowSelectorItem::OverviewLabelButton::GetChildAreaBounds() {
111 gfx::Rect bounds = GetLocalBounds();
112 bounds.Inset(0, top_padding_, 0, 0);
113 return bounds;
114 }
115
85 WindowSelectorItem::WindowSelectorItem(aura::Window* window) 116 WindowSelectorItem::WindowSelectorItem(aura::Window* window)
86 : dimmed_(false), 117 : dimmed_(false),
87 root_window_(window->GetRootWindow()), 118 root_window_(window->GetRootWindow()),
88 transform_window_(window), 119 transform_window_(window),
89 in_bounds_update_(false), 120 in_bounds_update_(false),
90 close_button_(new OverviewCloseButton(this)), 121 window_label_button_view_(nullptr),
91 overview_window_button_(new OverviewWindowButton(window)) { 122 close_button_(new OverviewCloseButton(this)) {
123 CreateWindowLabel(window->title());
92 views::Widget::InitParams params; 124 views::Widget::InitParams params;
93 params.type = views::Widget::InitParams::TYPE_POPUP; 125 params.type = views::Widget::InitParams::TYPE_POPUP;
94 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 126 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
95 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; 127 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
96 params.parent = Shell::GetContainer(root_window_, 128 params.parent = Shell::GetContainer(root_window_,
97 kShellWindowId_OverlayContainer); 129 kShellWindowId_OverlayContainer);
98 close_button_widget_.set_focus_on_creation(false); 130 close_button_widget_.set_focus_on_creation(false);
99 close_button_widget_.Init(params); 131 close_button_widget_.Init(params);
100 close_button_->SetVisible(false); 132 close_button_->SetVisible(false);
101 close_button_widget_.SetContentsView(close_button_); 133 close_button_widget_.SetContentsView(close_button_);
102 close_button_widget_.SetSize(close_button_->GetPreferredSize()); 134 close_button_widget_.SetSize(close_button_->GetPreferredSize());
103 close_button_widget_.Show(); 135 close_button_widget_.Show();
104 136
105 gfx::Rect close_button_rect(close_button_widget_.GetNativeWindow()->bounds()); 137 gfx::Rect close_button_rect(close_button_widget_.GetNativeWindow()->bounds());
106 // Align the center of the button with position (0, 0) so that the 138 // Align the center of the button with position (0, 0) so that the
107 // translate transform does not need to take the button dimensions into 139 // translate transform does not need to take the button dimensions into
108 // account. 140 // account.
109 close_button_rect.set_x(-close_button_rect.width() / 2); 141 close_button_rect.set_x(-close_button_rect.width() / 2);
110 close_button_rect.set_y(-close_button_rect.height() / 2); 142 close_button_rect.set_y(-close_button_rect.height() / 2);
111 close_button_widget_.GetNativeWindow()->SetBounds(close_button_rect); 143 close_button_widget_.GetNativeWindow()->SetBounds(close_button_rect);
112 144
113 GetWindow()->AddObserver(this); 145 GetWindow()->AddObserver(this);
114
115 UpdateCloseButtonAccessibilityName();
116 } 146 }
117 147
118 WindowSelectorItem::~WindowSelectorItem() { 148 WindowSelectorItem::~WindowSelectorItem() {
119 GetWindow()->RemoveObserver(this); 149 GetWindow()->RemoveObserver(this);
120 } 150 }
121 151
122 aura::Window* WindowSelectorItem::GetWindow() { 152 aura::Window* WindowSelectorItem::GetWindow() {
123 return transform_window_.window(); 153 return transform_window_.window();
124 } 154 }
125 155
(...skipping 13 matching lines...) Expand all
139 return transform_window_.Contains(target); 169 return transform_window_.Contains(target);
140 } 170 }
141 171
142 void WindowSelectorItem::SetBounds(const gfx::Rect& target_bounds, 172 void WindowSelectorItem::SetBounds(const gfx::Rect& target_bounds,
143 OverviewAnimationType animation_type) { 173 OverviewAnimationType animation_type) {
144 if (in_bounds_update_) 174 if (in_bounds_update_)
145 return; 175 return;
146 base::AutoReset<bool> auto_reset_in_bounds_update(&in_bounds_update_, true); 176 base::AutoReset<bool> auto_reset_in_bounds_update(&in_bounds_update_, true);
147 target_bounds_ = target_bounds; 177 target_bounds_ = target_bounds;
148 178
149 overview_window_button_->SetBounds(target_bounds, animation_type);
150
151 gfx::Rect inset_bounds(target_bounds); 179 gfx::Rect inset_bounds(target_bounds);
152 inset_bounds.Inset(kWindowMargin, kWindowMargin); 180 inset_bounds.Inset(kWindowMargin, kWindowMargin);
153 SetItemBounds(inset_bounds, animation_type); 181 SetItemBounds(inset_bounds, animation_type);
154 182
155 // SetItemBounds is called before UpdateCloseButtonLayout so the close button 183 // SetItemBounds is called before UpdateCloseButtonLayout so the close button
156 // can properly use the updated windows bounds. 184 // can properly use the updated windows bounds.
157 UpdateCloseButtonLayout(animation_type); 185 UpdateCloseButtonLayout(animation_type);
186 UpdateWindowLabel(target_bounds, animation_type);
158 } 187 }
159 188
160 void WindowSelectorItem::RecomputeWindowTransforms() { 189 void WindowSelectorItem::RecomputeWindowTransforms() {
161 if (in_bounds_update_ || target_bounds_.IsEmpty()) 190 if (in_bounds_update_ || target_bounds_.IsEmpty())
162 return; 191 return;
163 base::AutoReset<bool> auto_reset_in_bounds_update(&in_bounds_update_, true); 192 base::AutoReset<bool> auto_reset_in_bounds_update(&in_bounds_update_, true);
164 gfx::Rect inset_bounds(target_bounds_); 193 gfx::Rect inset_bounds(target_bounds_);
165 inset_bounds.Inset(kWindowMargin, kWindowMargin); 194 inset_bounds.Inset(kWindowMargin, kWindowMargin);
166 SetItemBounds(inset_bounds, OverviewAnimationType::OVERVIEW_ANIMATION_NONE); 195 SetItemBounds(inset_bounds, OverviewAnimationType::OVERVIEW_ANIMATION_NONE);
167 UpdateCloseButtonLayout(OverviewAnimationType::OVERVIEW_ANIMATION_NONE); 196 UpdateCloseButtonLayout(OverviewAnimationType::OVERVIEW_ANIMATION_NONE);
168 } 197 }
169 198
170 void WindowSelectorItem::SendFocusAlert() const { 199 void WindowSelectorItem::SendFocusAlert() const {
171 overview_window_button_->SendFocusAlert(); 200 window_label_button_view_->NotifyAccessibilityEvent(ui::AX_EVENT_FOCUS, true);
172 } 201 }
173 202
174 void WindowSelectorItem::SetDimmed(bool dimmed) { 203 void WindowSelectorItem::SetDimmed(bool dimmed) {
175 dimmed_ = dimmed; 204 dimmed_ = dimmed;
176 SetOpacity(dimmed ? kDimmedItemOpacity : 1.0f); 205 SetOpacity(dimmed ? kDimmedItemOpacity : 1.0f);
177 } 206 }
178 207
179 void WindowSelectorItem::ButtonPressed(views::Button* sender, 208 void WindowSelectorItem::ButtonPressed(views::Button* sender,
180 const ui::Event& event) { 209 const ui::Event& event) {
181 transform_window_.Close(); 210 if (sender == close_button_) {
211 transform_window_.Close();
212 return;
213 }
214 CHECK(sender == window_label_button_view_);
215 wm::GetWindowState(transform_window_.window())->Activate();
182 } 216 }
183 217
184 void WindowSelectorItem::OnWindowDestroying(aura::Window* window) { 218 void WindowSelectorItem::OnWindowDestroying(aura::Window* window) {
185 window->RemoveObserver(this); 219 window->RemoveObserver(this);
186 transform_window_.OnWindowDestroyed(); 220 transform_window_.OnWindowDestroyed();
187 } 221 }
188 222
189 void WindowSelectorItem::OnWindowTitleChanged(aura::Window* window) { 223 void WindowSelectorItem::OnWindowTitleChanged(aura::Window* window) {
190 // TODO(flackr): Maybe add the new title to a vector of titles so that we can 224 // TODO(flackr): Maybe add the new title to a vector of titles so that we can
191 // filter any of the titles the window had while in the overview session. 225 // filter any of the titles the window had while in the overview session.
192 overview_window_button_->SetLabelText(window->title()); 226 window_label_button_view_->SetText(window->title());
193 UpdateCloseButtonAccessibilityName(); 227 UpdateCloseButtonAccessibilityName();
194 } 228 }
195 229
196 void WindowSelectorItem::SetItemBounds(const gfx::Rect& target_bounds, 230 void WindowSelectorItem::SetItemBounds(const gfx::Rect& target_bounds,
197 OverviewAnimationType animation_type) { 231 OverviewAnimationType animation_type) {
198 DCHECK(root_window_ == GetWindow()->GetRootWindow()); 232 DCHECK(root_window_ == GetWindow()->GetRootWindow());
199 gfx::Rect screen_bounds = transform_window_.GetTargetBoundsInScreen(); 233 gfx::Rect screen_bounds = transform_window_.GetTargetBoundsInScreen();
200 gfx::Rect selector_item_bounds = 234 gfx::Rect selector_item_bounds =
201 ScopedTransformOverviewWindow::ShrinkRectToFitPreservingAspectRatio( 235 ScopedTransformOverviewWindow::ShrinkRectToFitPreservingAspectRatio(
202 screen_bounds, target_bounds); 236 screen_bounds, target_bounds);
203 gfx::Transform transform = 237 gfx::Transform transform =
204 ScopedTransformOverviewWindow::GetTransformForRect(screen_bounds, 238 ScopedTransformOverviewWindow::GetTransformForRect(screen_bounds,
205 selector_item_bounds); 239 selector_item_bounds);
206 ScopedTransformOverviewWindow::ScopedAnimationSettings animation_settings; 240 ScopedTransformOverviewWindow::ScopedAnimationSettings animation_settings;
207 transform_window_.BeginScopedAnimation(animation_type, &animation_settings); 241 transform_window_.BeginScopedAnimation(animation_type, &animation_settings);
208 transform_window_.SetTransform(root_window_, transform); 242 transform_window_.SetTransform(root_window_, transform);
209 transform_window_.set_overview_transform(transform); 243 transform_window_.set_overview_transform(transform);
210 } 244 }
211 245
212 void WindowSelectorItem::SetOpacity(float opacity) { 246 void WindowSelectorItem::SetOpacity(float opacity) {
213 overview_window_button_->SetOpacity(opacity); 247 window_label_->GetNativeWindow()->layer()->SetOpacity(opacity);
214 close_button_widget_.GetNativeWindow()->layer()->SetOpacity(opacity); 248 close_button_widget_.GetNativeWindow()->layer()->SetOpacity(opacity);
215 249
216 transform_window_.SetOpacity(opacity); 250 transform_window_.SetOpacity(opacity);
217 } 251 }
218 252
253 void WindowSelectorItem::UpdateWindowLabel(
254 const gfx::Rect& window_bounds,
255 OverviewAnimationType animation_type) {
256 // If the root window has changed, force the window label to be recreated
257 // and faded in on the new root window.
258 DCHECK(!window_label_ ||
259 window_label_->GetNativeWindow()->GetRootWindow() == root_window_);
260
261 if (!window_label_->IsVisible()) {
262 window_label_->Show();
263 ScopedOverviewAnimationSettings::SetupFadeInAfterLayout(
264 window_label_->GetNativeWindow());
265 }
266
267 gfx::Rect converted_bounds =
268 ScreenUtil::ConvertRectFromScreen(root_window_, window_bounds);
269 gfx::Rect label_bounds(converted_bounds.x(), converted_bounds.y(),
270 converted_bounds.width(), converted_bounds.height());
271 window_label_button_view_->set_top_padding(label_bounds.height() -
272 kVerticalLabelPadding);
273 ScopedOverviewAnimationSettings animation_settings(
274 animation_type, window_label_->GetNativeWindow());
275
276 window_label_->GetNativeWindow()->SetBounds(label_bounds);
277 }
278
279 void WindowSelectorItem::CreateWindowLabel(const base::string16& title) {
280 window_label_.reset(new views::Widget);
281 views::Widget::InitParams params;
282 params.type = views::Widget::InitParams::TYPE_POPUP;
283 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
284 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
285 params.parent =
286 Shell::GetContainer(root_window_, kShellWindowId_OverlayContainer);
287 params.visible_on_all_workspaces = true;
288 window_label_->set_focus_on_creation(false);
289 window_label_->Init(params);
290 window_label_button_view_ = new OverviewLabelButton(this, title);
291 window_label_button_view_->SetBorder(views::Border::NullBorder());
292 window_label_button_view_->SetTextColor(views::LabelButton::STATE_NORMAL,
293 kLabelColor);
294 window_label_button_view_->SetTextColor(views::LabelButton::STATE_HOVERED,
295 kLabelColor);
296 window_label_button_view_->SetTextColor(views::LabelButton::STATE_PRESSED,
297 kLabelColor);
298 window_label_button_view_->set_animate_on_state_change(false);
299 window_label_button_view_->SetHorizontalAlignment(gfx::ALIGN_CENTER);
300 window_label_button_view_->SetTextShadows(gfx::ShadowValues(
301 1, gfx::ShadowValue(gfx::Point(0, kVerticalShadowOffset), kShadowBlur,
302 kLabelShadow)));
303 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
304 window_label_button_view_->SetFontList(
305 bundle.GetFontList(ui::ResourceBundle::BoldFont));
306 window_label_->SetContentsView(window_label_button_view_);
307 }
308
219 void WindowSelectorItem::UpdateCloseButtonLayout( 309 void WindowSelectorItem::UpdateCloseButtonLayout(
220 OverviewAnimationType animation_type) { 310 OverviewAnimationType animation_type) {
221 if (!close_button_->visible()) { 311 if (!close_button_->visible()) {
222 close_button_->SetVisible(true); 312 close_button_->SetVisible(true);
223 ScopedOverviewAnimationSettings::SetupFadeInAfterLayout( 313 ScopedOverviewAnimationSettings::SetupFadeInAfterLayout(
224 close_button_widget_.GetNativeWindow()); 314 close_button_widget_.GetNativeWindow());
225 } 315 }
226 ScopedOverviewAnimationSettings animation_settings(animation_type, 316 ScopedOverviewAnimationSettings animation_settings(animation_type,
227 close_button_widget_.GetNativeWindow()); 317 close_button_widget_.GetNativeWindow());
228 318
229 gfx::Rect transformed_window_bounds = ScreenUtil::ConvertRectFromScreen( 319 gfx::Rect transformed_window_bounds = ScreenUtil::ConvertRectFromScreen(
230 close_button_widget_.GetNativeWindow()->GetRootWindow(), 320 close_button_widget_.GetNativeWindow()->GetRootWindow(),
231 GetTransformedBounds(GetWindow())); 321 GetTransformedBounds(GetWindow()));
232 322
233 gfx::Transform close_button_transform; 323 gfx::Transform close_button_transform;
234 close_button_transform.Translate(transformed_window_bounds.right(), 324 close_button_transform.Translate(transformed_window_bounds.right(),
235 transformed_window_bounds.y()); 325 transformed_window_bounds.y());
236 close_button_widget_.GetNativeWindow()->SetTransform( 326 close_button_widget_.GetNativeWindow()->SetTransform(
237 close_button_transform); 327 close_button_transform);
238 } 328 }
239 329
240 void WindowSelectorItem::UpdateCloseButtonAccessibilityName() { 330 void WindowSelectorItem::UpdateCloseButtonAccessibilityName() {
241 close_button_->SetAccessibleName(l10n_util::GetStringFUTF16( 331 close_button_->SetAccessibleName(l10n_util::GetStringFUTF16(
242 IDS_ASH_OVERVIEW_CLOSE_ITEM_BUTTON_ACCESSIBLE_NAME, 332 IDS_ASH_OVERVIEW_CLOSE_ITEM_BUTTON_ACCESSIBLE_NAME,
243 GetWindow()->title())); 333 GetWindow()->title()));
244 } 334 }
245 335
246 } // namespace ash 336 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/overview/window_selector_item.h ('k') | ash/wm/overview/window_selector_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698