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/shelf_button.h" | 5 #include "ash/common/shelf/shelf_button.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "ash/common/ash_constants.h" | 9 #include "ash/common/ash_constants.h" |
10 #include "ash/common/ash_switches.h" | |
11 #include "ash/common/material_design/material_design_controller.h" | 10 #include "ash/common/material_design/material_design_controller.h" |
12 #include "ash/common/shelf/ink_drop_button_listener.h" | 11 #include "ash/common/shelf/ink_drop_button_listener.h" |
13 #include "ash/common/shelf/shelf_constants.h" | 12 #include "ash/common/shelf/shelf_constants.h" |
14 #include "ash/shelf/shelf.h" | 13 #include "ash/common/shelf/wm_shelf.h" |
15 #include "ash/shelf/shelf_layout_manager.h" | 14 #include "ash/common/shelf/wm_shelf_util.h" |
16 #include "ash/shelf/shelf_view.h" | 15 #include "ash/shelf/shelf_view.h" |
17 #include "base/time/time.h" | 16 #include "base/time/time.h" |
18 #include "grit/ash_resources.h" | 17 #include "grit/ash_resources.h" |
19 #include "skia/ext/image_operations.h" | 18 #include "skia/ext/image_operations.h" |
20 #include "third_party/skia/include/core/SkPaint.h" | 19 #include "third_party/skia/include/core/SkPaint.h" |
21 #include "ui/accessibility/ax_view_state.h" | 20 #include "ui/accessibility/ax_view_state.h" |
22 #include "ui/base/resource/resource_bundle.h" | 21 #include "ui/base/resource/resource_bundle.h" |
23 #include "ui/compositor/layer.h" | 22 #include "ui/compositor/layer.h" |
24 #include "ui/compositor/scoped_layer_animation_settings.h" | 23 #include "ui/compositor/scoped_layer_animation_settings.h" |
25 #include "ui/events/event_constants.h" | 24 #include "ui/events/event_constants.h" |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 } // namespace | 129 } // namespace |
131 | 130 |
132 namespace ash { | 131 namespace ash { |
133 | 132 |
134 //////////////////////////////////////////////////////////////////////////////// | 133 //////////////////////////////////////////////////////////////////////////////// |
135 // ShelfButton::BarView | 134 // ShelfButton::BarView |
136 | 135 |
137 class ShelfButton::BarView : public views::ImageView, | 136 class ShelfButton::BarView : public views::ImageView, |
138 public ShelfButtonAnimation::Observer { | 137 public ShelfButtonAnimation::Observer { |
139 public: | 138 public: |
140 BarView(Shelf* shelf) | 139 BarView(WmShelf* wm_shelf) |
141 : shelf_(shelf), | 140 : wm_shelf_(wm_shelf), |
142 show_attention_(false), | 141 show_attention_(false), |
143 animation_end_time_(base::TimeTicks()), | 142 animation_end_time_(base::TimeTicks()), |
144 animating_(false) { | 143 animating_(false) { |
145 // Make sure the events reach the parent view for handling. | 144 // Make sure the events reach the parent view for handling. |
146 set_interactive(false); | 145 set_interactive(false); |
147 } | 146 } |
148 | 147 |
149 ~BarView() override { | 148 ~BarView() override { |
150 if (show_attention_) | 149 if (show_attention_) |
151 ShelfButtonAnimation::GetInstance()->RemoveObserver(this); | 150 ShelfButtonAnimation::GetInstance()->RemoveObserver(this); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 gfx::Rect bounds = base_bounds_; | 196 gfx::Rect bounds = base_bounds_; |
198 if (show_attention_) { | 197 if (show_attention_) { |
199 // Scale from .35 to 1.0 of the total width (which is wider than the | 198 // Scale from .35 to 1.0 of the total width (which is wider than the |
200 // visible width of the image), so the animation "rests" briefly at full | 199 // visible width of the image), so the animation "rests" briefly at full |
201 // visible width. Cap bounds length at kIconSize to prevent visual | 200 // visible width. Cap bounds length at kIconSize to prevent visual |
202 // flutter while centering bar within further expanding bounds. | 201 // flutter while centering bar within further expanding bounds. |
203 double animation = | 202 double animation = |
204 animating_ ? ShelfButtonAnimation::GetInstance()->GetAnimation() | 203 animating_ ? ShelfButtonAnimation::GetInstance()->GetAnimation() |
205 : 1.0; | 204 : 1.0; |
206 double scale = .35 + .65 * animation; | 205 double scale = .35 + .65 * animation; |
207 if (shelf_->IsHorizontalAlignment()) { | 206 if (IsHorizontalAlignment(wm_shelf_->GetAlignment())) { |
208 int width = base_bounds_.width() * scale; | 207 int width = base_bounds_.width() * scale; |
209 bounds.set_width(std::min(width, kIconSize)); | 208 bounds.set_width(std::min(width, kIconSize)); |
210 int x_offset = (base_bounds_.width() - bounds.width()) / 2; | 209 int x_offset = (base_bounds_.width() - bounds.width()) / 2; |
211 bounds.set_x(base_bounds_.x() + x_offset); | 210 bounds.set_x(base_bounds_.x() + x_offset); |
212 UpdateAnimating(bounds.width() == kIconSize); | 211 UpdateAnimating(bounds.width() == kIconSize); |
213 } else { | 212 } else { |
214 int height = base_bounds_.height() * scale; | 213 int height = base_bounds_.height() * scale; |
215 bounds.set_height(std::min(height, kIconSize)); | 214 bounds.set_height(std::min(height, kIconSize)); |
216 int y_offset = (base_bounds_.height() - bounds.height()) / 2; | 215 int y_offset = (base_bounds_.height() - bounds.height()) / 2; |
217 bounds.set_y(base_bounds_.y() + y_offset); | 216 bounds.set_y(base_bounds_.y() + y_offset); |
218 UpdateAnimating(bounds.height() == kIconSize); | 217 UpdateAnimating(bounds.height() == kIconSize); |
219 } | 218 } |
220 } | 219 } |
221 SetBoundsRect(bounds); | 220 SetBoundsRect(bounds); |
222 } | 221 } |
223 | 222 |
224 void UpdateAnimating(bool max_length) { | 223 void UpdateAnimating(bool max_length) { |
225 if (!max_length) | 224 if (!max_length) |
226 return; | 225 return; |
227 if (base::TimeTicks::Now() > animation_end_time_) { | 226 if (base::TimeTicks::Now() > animation_end_time_) { |
228 animating_ = false; | 227 animating_ = false; |
229 ShelfButtonAnimation::GetInstance()->RemoveObserver(this); | 228 ShelfButtonAnimation::GetInstance()->RemoveObserver(this); |
230 } | 229 } |
231 } | 230 } |
232 | 231 |
233 Shelf* shelf_; | 232 WmShelf* wm_shelf_; |
234 bool show_attention_; | 233 bool show_attention_; |
235 base::TimeTicks animation_end_time_; // For attention throbbing underline. | 234 base::TimeTicks animation_end_time_; // For attention throbbing underline. |
236 bool animating_; // Is time-limited attention animation running? | 235 bool animating_; // Is time-limited attention animation running? |
237 gfx::Rect base_bounds_; | 236 gfx::Rect base_bounds_; |
238 | 237 |
239 DISALLOW_COPY_AND_ASSIGN(BarView); | 238 DISALLOW_COPY_AND_ASSIGN(BarView); |
240 }; | 239 }; |
241 | 240 |
242 //////////////////////////////////////////////////////////////////////////////// | 241 //////////////////////////////////////////////////////////////////////////////// |
243 // ShelfButton | 242 // ShelfButton |
244 | 243 |
245 // static | 244 // static |
246 const char ShelfButton::kViewClassName[] = "ash/ShelfButton"; | 245 const char ShelfButton::kViewClassName[] = "ash/ShelfButton"; |
247 | 246 |
248 ShelfButton::ShelfButton(InkDropButtonListener* listener, ShelfView* shelf_view) | 247 ShelfButton::ShelfButton(InkDropButtonListener* listener, ShelfView* shelf_view) |
249 : CustomButton(nullptr), | 248 : CustomButton(nullptr), |
250 listener_(listener), | 249 listener_(listener), |
251 shelf_view_(shelf_view), | 250 shelf_view_(shelf_view), |
252 icon_view_(new views::ImageView()), | 251 icon_view_(new views::ImageView()), |
253 bar_(new BarView(shelf_view->shelf())), | 252 bar_(new BarView(shelf_view->wm_shelf())), |
254 state_(STATE_NORMAL), | 253 state_(STATE_NORMAL), |
255 destroyed_flag_(nullptr) { | 254 destroyed_flag_(nullptr) { |
256 SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY); | 255 SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY); |
257 if (ash::MaterialDesignController::IsShelfMaterial()) { | 256 if (ash::MaterialDesignController::IsShelfMaterial()) { |
258 SetInkDropMode(InkDropMode::ON); | 257 SetInkDropMode(InkDropMode::ON); |
259 set_ink_drop_base_color(kShelfInkDropBaseColor); | 258 set_ink_drop_base_color(kShelfInkDropBaseColor); |
260 set_ink_drop_visible_opacity(kShelfInkDropVisibleOpacity); | 259 set_ink_drop_visible_opacity(kShelfInkDropVisibleOpacity); |
261 } | 260 } |
262 | 261 |
263 const gfx::ShadowValue kShadows[] = { | 262 const gfx::ShadowValue kShadows[] = { |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 return true; | 390 return true; |
392 } | 391 } |
393 | 392 |
394 void ShelfButton::GetAccessibleState(ui::AXViewState* state) { | 393 void ShelfButton::GetAccessibleState(ui::AXViewState* state) { |
395 state->role = ui::AX_ROLE_BUTTON; | 394 state->role = ui::AX_ROLE_BUTTON; |
396 state->name = shelf_view_->GetTitleForView(this); | 395 state->name = shelf_view_->GetTitleForView(this); |
397 } | 396 } |
398 | 397 |
399 void ShelfButton::Layout() { | 398 void ShelfButton::Layout() { |
400 const gfx::Rect button_bounds(GetContentsBounds()); | 399 const gfx::Rect button_bounds(GetContentsBounds()); |
401 Shelf* shelf = shelf_view_->shelf(); | 400 WmShelf* wm_shelf = shelf_view_->wm_shelf(); |
402 int icon_pad = shelf->PrimaryAxisValue(kIconPad, kIconPadVertical); | 401 const bool is_horizontal_shelf = |
403 int x_offset = shelf->PrimaryAxisValue(0, icon_pad); | 402 IsHorizontalAlignment(wm_shelf->GetAlignment()); |
404 int y_offset = shelf->PrimaryAxisValue(icon_pad, 0); | 403 int icon_pad = is_horizontal_shelf ? kIconPad : kIconPadVertical; |
| 404 int x_offset = is_horizontal_shelf ? 0 : icon_pad; |
| 405 int y_offset = is_horizontal_shelf ? icon_pad : 0; |
405 | 406 |
406 int icon_width = std::min(kIconSize, button_bounds.width() - x_offset); | 407 int icon_width = std::min(kIconSize, button_bounds.width() - x_offset); |
407 int icon_height = std::min(kIconSize, button_bounds.height() - y_offset); | 408 int icon_height = std::min(kIconSize, button_bounds.height() - y_offset); |
408 | 409 |
409 // If on the left or top 'invert' the inset so the constant gap is on | 410 // If on the left or top 'invert' the inset so the constant gap is on |
410 // the interior (towards the center of display) edge of the shelf. | 411 // the interior (towards the center of display) edge of the shelf. |
411 if (SHELF_ALIGNMENT_LEFT == shelf->alignment()) | 412 if (SHELF_ALIGNMENT_LEFT == wm_shelf->GetAlignment()) |
412 x_offset = button_bounds.width() - (kIconSize + icon_pad); | 413 x_offset = button_bounds.width() - (kIconSize + icon_pad); |
413 | 414 |
414 // Center icon with respect to the secondary axis, and ensure | 415 // Center icon with respect to the secondary axis, and ensure |
415 // that the icon doesn't occlude the bar highlight. | 416 // that the icon doesn't occlude the bar highlight. |
416 if (shelf->IsHorizontalAlignment()) { | 417 if (is_horizontal_shelf) { |
417 x_offset = std::max(0, button_bounds.width() - icon_width) / 2; | 418 x_offset = std::max(0, button_bounds.width() - icon_width) / 2; |
418 if (y_offset + icon_height + kBarSize > button_bounds.height()) | 419 if (y_offset + icon_height + kBarSize > button_bounds.height()) |
419 icon_height = button_bounds.height() - (y_offset + kBarSize); | 420 icon_height = button_bounds.height() - (y_offset + kBarSize); |
420 } else { | 421 } else { |
421 y_offset = std::max(0, button_bounds.height() - icon_height) / 2; | 422 y_offset = std::max(0, button_bounds.height() - icon_height) / 2; |
422 if (x_offset + icon_width + kBarSize > button_bounds.width()) | 423 if (x_offset + icon_width + kBarSize > button_bounds.width()) |
423 icon_width = button_bounds.width() - (x_offset + kBarSize); | 424 icon_width = button_bounds.width() - (x_offset + kBarSize); |
424 } | 425 } |
425 | 426 |
426 // Expand bounds to include shadows. | 427 // Expand bounds to include shadows. |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
515 } | 516 } |
516 | 517 |
517 void ShelfButton::NotifyClick(const ui::Event& event) { | 518 void ShelfButton::NotifyClick(const ui::Event& event) { |
518 CustomButton::NotifyClick(event); | 519 CustomButton::NotifyClick(event); |
519 if (listener_) | 520 if (listener_) |
520 listener_->ButtonPressed(this, event, ink_drop()); | 521 listener_->ButtonPressed(this, event, ink_drop()); |
521 } | 522 } |
522 | 523 |
523 void ShelfButton::UpdateState() { | 524 void ShelfButton::UpdateState() { |
524 UpdateBar(); | 525 UpdateBar(); |
525 Shelf* shelf = shelf_view_->shelf(); | 526 const bool is_horizontal_shelf = |
526 icon_view_->SetHorizontalAlignment(shelf->PrimaryAxisValue( | 527 IsHorizontalAlignment(shelf_view_->wm_shelf()->GetAlignment()); |
527 views::ImageView::CENTER, views::ImageView::LEADING)); | 528 icon_view_->SetHorizontalAlignment(is_horizontal_shelf |
528 icon_view_->SetVerticalAlignment(shelf->PrimaryAxisValue( | 529 ? views::ImageView::CENTER |
529 views::ImageView::LEADING, views::ImageView::CENTER)); | 530 : views::ImageView::LEADING); |
| 531 icon_view_->SetVerticalAlignment(is_horizontal_shelf |
| 532 ? views::ImageView::LEADING |
| 533 : views::ImageView::CENTER); |
530 SchedulePaint(); | 534 SchedulePaint(); |
531 } | 535 } |
532 | 536 |
533 void ShelfButton::UpdateBar() { | 537 void ShelfButton::UpdateBar() { |
534 if (state_ & STATE_HIDDEN) { | 538 if (state_ & STATE_HIDDEN) { |
535 bar_->SetVisible(false); | 539 bar_->SetVisible(false); |
536 return; | 540 return; |
537 } | 541 } |
538 | 542 |
539 int bar_id = 0; | 543 int bar_id = 0; |
540 if (state_ & (STATE_ACTIVE)) | 544 if (state_ & (STATE_ACTIVE)) |
541 bar_id = IDR_ASH_SHELF_UNDERLINE_ACTIVE; | 545 bar_id = IDR_ASH_SHELF_UNDERLINE_ACTIVE; |
542 else if (state_ & STATE_ATTENTION) | 546 else if (state_ & STATE_ATTENTION) |
543 bar_id = IDR_ASH_SHELF_UNDERLINE_ATTENTION; | 547 bar_id = IDR_ASH_SHELF_UNDERLINE_ATTENTION; |
544 else if (state_ & STATE_RUNNING) | 548 else if (state_ & STATE_RUNNING) |
545 bar_id = IDR_ASH_SHELF_UNDERLINE_RUNNING; | 549 bar_id = IDR_ASH_SHELF_UNDERLINE_RUNNING; |
546 | 550 |
547 if (bar_id != 0) { | 551 if (bar_id != 0) { |
548 Shelf* shelf = shelf_view_->shelf(); | 552 WmShelf* wm_shelf = shelf_view_->wm_shelf(); |
549 gfx::ImageSkia image; | 553 gfx::ImageSkia image; |
550 if (ash::MaterialDesignController::IsShelfMaterial()) { | 554 if (ash::MaterialDesignController::IsShelfMaterial()) { |
551 if (shelf->shelf_widget()->shelf_layout_manager()->IsVisible()) { | 555 if (wm_shelf->IsVisible()) { |
552 gfx::Size size(GetShelfConstant(SHELF_BUTTON_SIZE), | 556 gfx::Size size(GetShelfConstant(SHELF_BUTTON_SIZE), |
553 GetShelfConstant(SHELF_SIZE)); | 557 GetShelfConstant(SHELF_SIZE)); |
554 gfx::Canvas canvas(size, kIndicatorCanvasScale, true /* is_opaque */); | 558 gfx::Canvas canvas(size, kIndicatorCanvasScale, true /* is_opaque */); |
555 PaintIndicatorOnCanvas(&canvas, size); | 559 PaintIndicatorOnCanvas(&canvas, size); |
556 image = gfx::ImageSkia(canvas.ExtractImageRep()); | 560 image = gfx::ImageSkia(canvas.ExtractImageRep()); |
557 } | 561 } |
558 } else { | 562 } else { |
559 ResourceBundle* rb = &ResourceBundle::GetSharedInstance(); | 563 ResourceBundle* rb = &ResourceBundle::GetSharedInstance(); |
560 image = *rb->GetImageNamed(bar_id).ToImageSkia(); | 564 image = *rb->GetImageNamed(bar_id).ToImageSkia(); |
561 } | 565 } |
562 if (!shelf->IsHorizontalAlignment()) { | 566 ShelfAlignment shelf_alignment = wm_shelf->GetAlignment(); |
| 567 if (!IsHorizontalAlignment(shelf_alignment)) { |
563 image = gfx::ImageSkiaOperations::CreateRotatedImage( | 568 image = gfx::ImageSkiaOperations::CreateRotatedImage( |
564 image, shelf->alignment() == SHELF_ALIGNMENT_LEFT | 569 image, shelf_alignment == SHELF_ALIGNMENT_LEFT |
565 ? SkBitmapOperations::ROTATION_90_CW | 570 ? SkBitmapOperations::ROTATION_90_CW |
566 : SkBitmapOperations::ROTATION_270_CW); | 571 : SkBitmapOperations::ROTATION_270_CW); |
567 } | 572 } |
568 bar_->SetImage(image); | 573 bar_->SetImage(image); |
569 bar_->SetHorizontalAlignment(shelf->SelectValueForShelfAlignment( | 574 switch (shelf_alignment) { |
570 views::ImageView::CENTER, views::ImageView::LEADING, | 575 case SHELF_ALIGNMENT_BOTTOM: |
571 views::ImageView::TRAILING)); | 576 case SHELF_ALIGNMENT_BOTTOM_LOCKED: |
572 bar_->SetVerticalAlignment(shelf->SelectValueForShelfAlignment( | 577 bar_->SetHorizontalAlignment(views::ImageView::CENTER); |
573 views::ImageView::TRAILING, views::ImageView::CENTER, | 578 bar_->SetVerticalAlignment(views::ImageView::TRAILING); |
574 views::ImageView::CENTER)); | 579 break; |
| 580 case SHELF_ALIGNMENT_LEFT: |
| 581 bar_->SetHorizontalAlignment(views::ImageView::LEADING); |
| 582 bar_->SetVerticalAlignment(views::ImageView::CENTER); |
| 583 break; |
| 584 case SHELF_ALIGNMENT_RIGHT: |
| 585 bar_->SetHorizontalAlignment(views::ImageView::TRAILING); |
| 586 bar_->SetVerticalAlignment(views::ImageView::CENTER); |
| 587 break; |
| 588 } |
575 bar_->SchedulePaint(); | 589 bar_->SchedulePaint(); |
576 } | 590 } |
577 bar_->SetVisible(bar_id != 0 && state_ != STATE_NORMAL); | 591 bar_->SetVisible(bar_id != 0 && state_ != STATE_NORMAL); |
578 } | 592 } |
579 | 593 |
580 } // namespace ash | 594 } // namespace ash |
OLD | NEW |