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

Unified Diff: mash/shelf/shelf_button.cc

Issue 1585363002: Fork a subset of ash/shelf for use in mash. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Revert ash changes. Created 4 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: mash/shelf/shelf_button.cc
diff --git a/ash/shelf/shelf_button.cc b/mash/shelf/shelf_button.cc
similarity index 86%
copy from ash/shelf/shelf_button.cc
copy to mash/shelf/shelf_button.cc
index 6329694252efa0a26292d48e38f2e76e7c9c03c4..d2b6fbe63097cfefe288d3b810b4e2a40d23eefa 100644
--- a/ash/shelf/shelf_button.cc
+++ b/mash/shelf/shelf_button.cc
@@ -2,16 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "ash/shelf/shelf_button.h"
+#include "mash/shelf/shelf_button.h"
#include <algorithm>
-#include "ash/ash_constants.h"
-#include "ash/ash_switches.h"
-#include "ash/shelf/shelf_button_host.h"
-#include "ash/shelf/shelf_layout_manager.h"
#include "base/time/time.h"
-#include "grit/ash_resources.h"
+#include "mash/shelf/shelf_button_host.h"
#include "skia/ext/image_operations.h"
#include "ui/accessibility/ax_view_state.h"
#include "ui/base/resource/resource_bundle.h"
@@ -107,7 +103,8 @@ class ShelfButtonAnimation : public gfx::AnimationDelegate {
} // namespace
-namespace ash {
+namespace mash {
+namespace shelf {
////////////////////////////////////////////////////////////////////////////////
// ShelfButton::BarView
@@ -180,8 +177,7 @@ class ShelfButton::BarView : public views::ImageView,
double animation = animating_ ?
ShelfButtonAnimation::GetInstance()->GetAnimation() : 1.0;
double scale = .35 + .65 * animation;
- if (host_->shelf_layout_manager()->GetAlignment() ==
- SHELF_ALIGNMENT_BOTTOM) {
+ if (host_->host()->GetAlignment() == SHELF_ALIGNMENT_BOTTOM) {
int width = base_bounds_.width() * scale;
bounds.set_width(std::min(width, kIconSize));
int x_offset = (base_bounds_.width() - bounds.width()) / 2;
@@ -235,22 +231,19 @@ ShelfButton::IconView::~IconView() {
const char ShelfButton::kViewClassName[] = "ash/ShelfButton";
ShelfButton* ShelfButton::Create(views::ButtonListener* listener,
- ShelfButtonHost* host,
- ShelfLayoutManager* shelf_layout_manager) {
- ShelfButton* button = new ShelfButton(listener, host, shelf_layout_manager);
+ ShelfButtonHost* host) {
+ ShelfButton* button = new ShelfButton(listener, host);
button->Init();
return button;
}
ShelfButton::ShelfButton(views::ButtonListener* listener,
- ShelfButtonHost* host,
- ShelfLayoutManager* shelf_layout_manager)
+ ShelfButtonHost* host)
: CustomButton(listener),
host_(host),
icon_view_(NULL),
bar_(new BarView(this)),
state_(STATE_NORMAL),
- shelf_layout_manager_(shelf_layout_manager),
destroyed_flag_(NULL) {
SetAccessibilityFocusable(true);
@@ -402,11 +395,10 @@ void ShelfButton::GetAccessibleState(ui::AXViewState* state) {
void ShelfButton::Layout() {
const gfx::Rect button_bounds(GetContentsBounds());
- int icon_pad =
- shelf_layout_manager_->GetAlignment() != SHELF_ALIGNMENT_BOTTOM ?
+ int icon_pad = host_->GetAlignment() != SHELF_ALIGNMENT_BOTTOM ?
kIconPadVertical : kIconPad;
- int x_offset = shelf_layout_manager_->PrimaryAxisValue(0, icon_pad);
- int y_offset = shelf_layout_manager_->PrimaryAxisValue(icon_pad, 0);
+ int x_offset = host_->PrimaryAxisValue(0, icon_pad);
+ int y_offset = host_->PrimaryAxisValue(icon_pad, 0);
int icon_width = std::min(kIconSize,
button_bounds.width() - x_offset);
@@ -415,15 +407,15 @@ void ShelfButton::Layout() {
// If on the left or top 'invert' the inset so the constant gap is on
// the interior (towards the center of display) edge of the shelf.
- if (SHELF_ALIGNMENT_LEFT == shelf_layout_manager_->GetAlignment())
+ if (SHELF_ALIGNMENT_LEFT == host_->GetAlignment())
x_offset = button_bounds.width() - (kIconSize + icon_pad);
- if (SHELF_ALIGNMENT_TOP == shelf_layout_manager_->GetAlignment())
+ if (SHELF_ALIGNMENT_TOP == host_->GetAlignment())
y_offset = button_bounds.height() - (kIconSize + icon_pad);
// Center icon with respect to the secondary axis, and ensure
// that the icon doesn't occlude the bar highlight.
- if (shelf_layout_manager_->IsHorizontalAlignment()) {
+ if (host_->IsHorizontalAlignment()) {
x_offset = std::max(0, button_bounds.width() - icon_width) / 2;
if (y_offset + icon_height + kBarSize > button_bounds.height())
icon_height = button_bounds.height() - (y_offset + kBarSize);
@@ -474,6 +466,7 @@ void ShelfButton::OnPaint(gfx::Canvas* canvas) {
if (HasFocus()) {
gfx::Rect paint_bounds(GetLocalBounds());
paint_bounds.Inset(1, 1, 1, 1);
+ const SkColor kFocusBorderColor = SkColorSetRGB(64, 128, 250);
canvas->DrawSolidFocusRect(paint_bounds, kFocusBorderColor);
}
}
@@ -520,19 +513,13 @@ ShelfButton::IconView* ShelfButton::CreateIconView() {
return new IconView;
}
-bool ShelfButton::IsShelfHorizontal() const {
- return shelf_layout_manager_->IsHorizontalAlignment();
-}
-
void ShelfButton::UpdateState() {
UpdateBar();
- icon_view_->SetHorizontalAlignment(
- shelf_layout_manager_->PrimaryAxisValue(views::ImageView::CENTER,
- views::ImageView::LEADING));
- icon_view_->SetVerticalAlignment(
- shelf_layout_manager_->PrimaryAxisValue(views::ImageView::LEADING,
- views::ImageView::CENTER));
+ icon_view_->SetHorizontalAlignment(host_->PrimaryAxisValue(
+ views::ImageView::CENTER, views::ImageView::LEADING));
+ icon_view_->SetVerticalAlignment(host_->PrimaryAxisValue(
+ views::ImageView::LEADING, views::ImageView::CENTER));
SchedulePaint();
}
@@ -543,42 +530,38 @@ void ShelfButton::UpdateBar() {
}
int bar_id = 0;
- if (state_ & (STATE_ACTIVE))
- bar_id = IDR_ASH_SHELF_UNDERLINE_ACTIVE;
- else if (state_ & STATE_ATTENTION)
- bar_id = IDR_ASH_SHELF_UNDERLINE_ATTENTION;
- else if (state_ & STATE_RUNNING)
- bar_id = IDR_ASH_SHELF_UNDERLINE_RUNNING;
+ // TODO(msw): Restore shelf button bar images.
msw 2016/01/27 07:43:41 Standardize commenting.
+ // if (state_ & (STATE_ACTIVE))
+ // bar_id = IDR_ASH_SHELF_UNDERLINE_ACTIVE;
+ // else if (state_ & STATE_ATTENTION)
+ // bar_id = IDR_ASH_SHELF_UNDERLINE_ATTENTION;
+ // else if (state_ & STATE_RUNNING)
+ // bar_id = IDR_ASH_SHELF_UNDERLINE_RUNNING;
if (bar_id != 0) {
ResourceBundle& rb = ResourceBundle::GetSharedInstance();
const gfx::ImageSkia* image = rb.GetImageNamed(bar_id).ToImageSkia();
- if (shelf_layout_manager_->GetAlignment() == SHELF_ALIGNMENT_BOTTOM) {
+ if (host_->GetAlignment() == SHELF_ALIGNMENT_BOTTOM) {
bar_->SetImage(*image);
} else {
bar_->SetImage(gfx::ImageSkiaOperations::CreateRotatedImage(*image,
- shelf_layout_manager_->SelectValueForShelfAlignment(
+ host_->SelectValueForShelfAlignment(
SkBitmapOperations::ROTATION_90_CW,
SkBitmapOperations::ROTATION_90_CW,
SkBitmapOperations::ROTATION_270_CW,
SkBitmapOperations::ROTATION_180_CW)));
}
- bar_->SetHorizontalAlignment(
- shelf_layout_manager_->SelectValueForShelfAlignment(
- views::ImageView::CENTER,
- views::ImageView::LEADING,
- views::ImageView::TRAILING,
- views::ImageView::CENTER));
- bar_->SetVerticalAlignment(
- shelf_layout_manager_->SelectValueForShelfAlignment(
- views::ImageView::TRAILING,
- views::ImageView::CENTER,
- views::ImageView::CENTER,
- views::ImageView::LEADING));
+ bar_->SetHorizontalAlignment(host_->SelectValueForShelfAlignment(
+ views::ImageView::CENTER, views::ImageView::LEADING,
+ views::ImageView::TRAILING, views::ImageView::CENTER));
+ bar_->SetVerticalAlignment(host_->SelectValueForShelfAlignment(
+ views::ImageView::TRAILING, views::ImageView::CENTER,
+ views::ImageView::CENTER, views::ImageView::LEADING));
bar_->SchedulePaint();
}
bar_->SetVisible(bar_id != 0 && state_ != STATE_NORMAL);
}
-} // namespace ash
+} // namespace shelf
+} // namespace mash

Powered by Google App Engine
This is Rietveld 408576698