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

Side by Side Diff: ash/common/shelf/shelf_button.cc

Issue 2676673005: ash: Clean up shelf GetAlignment() and IsHorizontalAlignment() calls (Closed)
Patch Set: Created 3 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/common/shelf/overflow_bubble_view.cc ('k') | ash/common/shelf/shelf_layout_manager.h » ('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/common/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/material_design/material_design_controller.h" 10 #include "ash/common/material_design/material_design_controller.h"
11 #include "ash/common/shelf/ink_drop_button_listener.h" 11 #include "ash/common/shelf/ink_drop_button_listener.h"
12 #include "ash/common/shelf/shelf_constants.h" 12 #include "ash/common/shelf/shelf_constants.h"
13 #include "ash/common/shelf/shelf_view.h" 13 #include "ash/common/shelf/shelf_view.h"
14 #include "ash/common/shelf/wm_shelf.h" 14 #include "ash/common/shelf/wm_shelf.h"
15 #include "ash/common/shelf/wm_shelf_util.h"
16 #include "base/memory/ptr_util.h" 15 #include "base/memory/ptr_util.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_node_data.h" 20 #include "ui/accessibility/ax_node_data.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 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 gfx::Rect bounds = base_bounds_; 201 gfx::Rect bounds = base_bounds_;
203 if (show_attention_) { 202 if (show_attention_) {
204 // Scale from .35 to 1.0 of the total width (which is wider than the 203 // Scale from .35 to 1.0 of the total width (which is wider than the
205 // visible width of the image), so the animation "rests" briefly at full 204 // visible width of the image), so the animation "rests" briefly at full
206 // visible width. Cap bounds length at kIconSize to prevent visual 205 // visible width. Cap bounds length at kIconSize to prevent visual
207 // flutter while centering bar within further expanding bounds. 206 // flutter while centering bar within further expanding bounds.
208 double animation = 207 double animation =
209 animating_ ? ShelfButtonAnimation::GetInstance()->GetAnimation() 208 animating_ ? ShelfButtonAnimation::GetInstance()->GetAnimation()
210 : 1.0; 209 : 1.0;
211 double scale = .35 + .65 * animation; 210 double scale = .35 + .65 * animation;
212 if (IsHorizontalAlignment(wm_shelf_->GetAlignment())) { 211 if (wm_shelf_->IsHorizontalAlignment()) {
213 int width = base_bounds_.width() * scale; 212 int width = base_bounds_.width() * scale;
214 bounds.set_width(std::min(width, kIconSize)); 213 bounds.set_width(std::min(width, kIconSize));
215 int x_offset = (base_bounds_.width() - bounds.width()) / 2; 214 int x_offset = (base_bounds_.width() - bounds.width()) / 2;
216 bounds.set_x(base_bounds_.x() + x_offset); 215 bounds.set_x(base_bounds_.x() + x_offset);
217 UpdateAnimating(bounds.width() == kIconSize); 216 UpdateAnimating(bounds.width() == kIconSize);
218 } else { 217 } else {
219 int height = base_bounds_.height() * scale; 218 int height = base_bounds_.height() * scale;
220 bounds.set_height(std::min(height, kIconSize)); 219 bounds.set_height(std::min(height, kIconSize));
221 int y_offset = (base_bounds_.height() - bounds.height()) / 2; 220 int y_offset = (base_bounds_.height() - bounds.height()) / 2;
222 bounds.set_y(base_bounds_.y() + y_offset); 221 bounds.set_y(base_bounds_.y() + y_offset);
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 } 396 }
398 397
399 void ShelfButton::GetAccessibleNodeData(ui::AXNodeData* node_data) { 398 void ShelfButton::GetAccessibleNodeData(ui::AXNodeData* node_data) {
400 node_data->role = ui::AX_ROLE_BUTTON; 399 node_data->role = ui::AX_ROLE_BUTTON;
401 node_data->SetName(shelf_view_->GetTitleForView(this)); 400 node_data->SetName(shelf_view_->GetTitleForView(this));
402 } 401 }
403 402
404 void ShelfButton::Layout() { 403 void ShelfButton::Layout() {
405 const gfx::Rect button_bounds(GetContentsBounds()); 404 const gfx::Rect button_bounds(GetContentsBounds());
406 WmShelf* wm_shelf = shelf_view_->wm_shelf(); 405 WmShelf* wm_shelf = shelf_view_->wm_shelf();
407 const bool is_horizontal_shelf = 406 const bool is_horizontal_shelf = wm_shelf->IsHorizontalAlignment();
408 IsHorizontalAlignment(wm_shelf->GetAlignment());
409 const int icon_pad = ash::MaterialDesignController::IsShelfMaterial() 407 const int icon_pad = ash::MaterialDesignController::IsShelfMaterial()
410 ? (is_horizontal_shelf ? kIconPaddingHorizontalMD 408 ? (is_horizontal_shelf ? kIconPaddingHorizontalMD
411 : kIconPaddingVerticalMD) 409 : kIconPaddingVerticalMD)
412 : (is_horizontal_shelf ? kIconPaddingHorizontal 410 : (is_horizontal_shelf ? kIconPaddingHorizontal
413 : kIconPaddingVertical); 411 : kIconPaddingVertical);
414 int x_offset = is_horizontal_shelf ? 0 : icon_pad; 412 int x_offset = is_horizontal_shelf ? 0 : icon_pad;
415 int y_offset = is_horizontal_shelf ? icon_pad : 0; 413 int y_offset = is_horizontal_shelf ? icon_pad : 0;
416 414
417 int icon_width = std::min(kIconSize, button_bounds.width() - x_offset); 415 int icon_width = std::min(kIconSize, button_bounds.width() - x_offset);
418 int icon_height = std::min(kIconSize, button_bounds.height() - y_offset); 416 int icon_height = std::min(kIconSize, button_bounds.height() - y_offset);
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 528
531 void ShelfButton::NotifyClick(const ui::Event& event) { 529 void ShelfButton::NotifyClick(const ui::Event& event) {
532 CustomButton::NotifyClick(event); 530 CustomButton::NotifyClick(event);
533 if (listener_) 531 if (listener_)
534 listener_->ButtonPressed(this, event, GetInkDrop()); 532 listener_->ButtonPressed(this, event, GetInkDrop());
535 } 533 }
536 534
537 void ShelfButton::UpdateState() { 535 void ShelfButton::UpdateState() {
538 UpdateBar(); 536 UpdateBar();
539 const bool is_horizontal_shelf = 537 const bool is_horizontal_shelf =
540 IsHorizontalAlignment(shelf_view_->wm_shelf()->GetAlignment()); 538 shelf_view_->wm_shelf()->IsHorizontalAlignment();
541 icon_view_->SetHorizontalAlignment(is_horizontal_shelf 539 icon_view_->SetHorizontalAlignment(is_horizontal_shelf
542 ? views::ImageView::CENTER 540 ? views::ImageView::CENTER
543 : views::ImageView::LEADING); 541 : views::ImageView::LEADING);
544 icon_view_->SetVerticalAlignment(is_horizontal_shelf 542 icon_view_->SetVerticalAlignment(is_horizontal_shelf
545 ? views::ImageView::LEADING 543 ? views::ImageView::LEADING
546 : views::ImageView::CENTER); 544 : views::ImageView::CENTER);
547 SchedulePaint(); 545 SchedulePaint();
548 } 546 }
549 547
550 void ShelfButton::UpdateBar() { 548 void ShelfButton::UpdateBar() {
(...skipping 19 matching lines...) Expand all
570 GetShelfConstant(SHELF_SIZE)); 568 GetShelfConstant(SHELF_SIZE));
571 gfx::Canvas canvas(size, kIndicatorCanvasScale, true /* is_opaque */); 569 gfx::Canvas canvas(size, kIndicatorCanvasScale, true /* is_opaque */);
572 PaintIndicatorOnCanvas(&canvas, size); 570 PaintIndicatorOnCanvas(&canvas, size);
573 image = gfx::ImageSkia(canvas.ExtractImageRep()); 571 image = gfx::ImageSkia(canvas.ExtractImageRep());
574 } 572 }
575 } else { 573 } else {
576 ResourceBundle* rb = &ResourceBundle::GetSharedInstance(); 574 ResourceBundle* rb = &ResourceBundle::GetSharedInstance();
577 image = *rb->GetImageNamed(bar_id).ToImageSkia(); 575 image = *rb->GetImageNamed(bar_id).ToImageSkia();
578 } 576 }
579 ShelfAlignment shelf_alignment = wm_shelf->GetAlignment(); 577 ShelfAlignment shelf_alignment = wm_shelf->GetAlignment();
580 if (!IsHorizontalAlignment(shelf_alignment)) { 578 if (!wm_shelf->IsHorizontalAlignment()) {
581 image = gfx::ImageSkiaOperations::CreateRotatedImage( 579 image = gfx::ImageSkiaOperations::CreateRotatedImage(
582 image, shelf_alignment == SHELF_ALIGNMENT_LEFT 580 image, shelf_alignment == SHELF_ALIGNMENT_LEFT
583 ? SkBitmapOperations::ROTATION_90_CW 581 ? SkBitmapOperations::ROTATION_90_CW
584 : SkBitmapOperations::ROTATION_270_CW); 582 : SkBitmapOperations::ROTATION_270_CW);
585 } 583 }
586 bar_->SetImage(image); 584 bar_->SetImage(image);
587 switch (shelf_alignment) { 585 switch (shelf_alignment) {
588 case SHELF_ALIGNMENT_BOTTOM: 586 case SHELF_ALIGNMENT_BOTTOM:
589 case SHELF_ALIGNMENT_BOTTOM_LOCKED: 587 case SHELF_ALIGNMENT_BOTTOM_LOCKED:
590 bar_->SetHorizontalAlignment(views::ImageView::CENTER); 588 bar_->SetHorizontalAlignment(views::ImageView::CENTER);
591 bar_->SetVerticalAlignment(views::ImageView::TRAILING); 589 bar_->SetVerticalAlignment(views::ImageView::TRAILING);
592 break; 590 break;
593 case SHELF_ALIGNMENT_LEFT: 591 case SHELF_ALIGNMENT_LEFT:
594 bar_->SetHorizontalAlignment(views::ImageView::LEADING); 592 bar_->SetHorizontalAlignment(views::ImageView::LEADING);
595 bar_->SetVerticalAlignment(views::ImageView::CENTER); 593 bar_->SetVerticalAlignment(views::ImageView::CENTER);
596 break; 594 break;
597 case SHELF_ALIGNMENT_RIGHT: 595 case SHELF_ALIGNMENT_RIGHT:
598 bar_->SetHorizontalAlignment(views::ImageView::TRAILING); 596 bar_->SetHorizontalAlignment(views::ImageView::TRAILING);
599 bar_->SetVerticalAlignment(views::ImageView::CENTER); 597 bar_->SetVerticalAlignment(views::ImageView::CENTER);
600 break; 598 break;
601 } 599 }
602 bar_->SchedulePaint(); 600 bar_->SchedulePaint();
603 } 601 }
604 bar_->SetVisible(bar_id != 0 && state_ != STATE_NORMAL); 602 bar_->SetVisible(bar_id != 0 && state_ != STATE_NORMAL);
605 } 603 }
606 604
607 } // namespace ash 605 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/shelf/overflow_bubble_view.cc ('k') | ash/common/shelf/shelf_layout_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698