OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/launcher/overflow_button.h" | 5 #include "ash/launcher/overflow_button.h" |
6 | 6 |
| 7 #include "ash/wm/shelf_layout_manager.h" |
7 #include "grit/ash_resources.h" | 8 #include "grit/ash_resources.h" |
8 #include "grit/ash_strings.h" | 9 #include "grit/ash_strings.h" |
9 #include "third_party/skia/include/core/SkPaint.h" | 10 #include "third_party/skia/include/core/SkPaint.h" |
10 #include "third_party/skia/include/core/SkPath.h" | 11 #include "third_party/skia/include/core/SkPath.h" |
11 #include "ui/base/animation/throb_animation.h" | 12 #include "ui/base/animation/throb_animation.h" |
12 #include "ui/base/l10n/l10n_util.h" | 13 #include "ui/base/l10n/l10n_util.h" |
13 #include "ui/base/resource/resource_bundle.h" | 14 #include "ui/base/resource/resource_bundle.h" |
14 #include "ui/gfx/canvas.h" | 15 #include "ui/gfx/canvas.h" |
15 #include "ui/gfx/skia_util.h" | 16 #include "ui/gfx/skia_util.h" |
16 #include "ui/gfx/transform.h" | 17 #include "ui/gfx/transform.h" |
| 18 #include "ui/views/widget/widget.h" |
17 | 19 |
18 namespace ash { | 20 namespace ash { |
19 namespace internal { | 21 namespace internal { |
20 | 22 |
21 namespace { | 23 namespace { |
22 | 24 |
23 const int kButtonHoverAlpha = 150; | 25 const int kButtonHoverAlpha = 150; |
24 | 26 |
25 const int kButtonCornerRadius = 2; | 27 const int kButtonCornerRadius = 2; |
26 | 28 |
(...skipping 14 matching lines...) Expand all Loading... |
41 rotation.set3x3( 0, 1, 0, | 43 rotation.set3x3( 0, 1, 0, |
42 -1, 0, 0, | 44 -1, 0, 0, |
43 0, 0, 1); | 45 0, 0, 1); |
44 transform->matrix().preConcat(rotation); | 46 transform->matrix().preConcat(rotation); |
45 } | 47 } |
46 | 48 |
47 } // namesapce | 49 } // namesapce |
48 | 50 |
49 OverflowButton::OverflowButton(views::ButtonListener* listener) | 51 OverflowButton::OverflowButton(views::ButtonListener* listener) |
50 : CustomButton(listener), | 52 : CustomButton(listener), |
51 alignment_(SHELF_ALIGNMENT_BOTTOM), | |
52 image_(NULL) { | 53 image_(NULL) { |
53 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 54 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
54 image_ = rb.GetImageNamed(IDR_AURA_LAUNCHER_OVERFLOW).ToImageSkia(); | 55 image_ = rb.GetImageNamed(IDR_AURA_LAUNCHER_OVERFLOW).ToImageSkia(); |
55 | 56 |
56 set_accessibility_focusable(true); | 57 set_accessibility_focusable(true); |
57 SetAccessibleName( | 58 SetAccessibleName( |
58 l10n_util::GetStringUTF16(IDS_AURA_LAUNCHER_OVERFLOW_NAME)); | 59 l10n_util::GetStringUTF16(IDS_AURA_LAUNCHER_OVERFLOW_NAME)); |
59 } | 60 } |
60 | 61 |
61 | 62 |
62 OverflowButton::~OverflowButton() { | 63 OverflowButton::~OverflowButton() { |
63 } | 64 } |
64 | 65 |
65 void OverflowButton::SetShelfAlignment(ShelfAlignment alignment) { | 66 void OverflowButton::OnShelfAlignmentChanged() { |
66 if (alignment_ == alignment) | |
67 return; | |
68 | |
69 alignment_ = alignment; | |
70 SchedulePaint(); | 67 SchedulePaint(); |
71 } | 68 } |
72 | 69 |
73 void OverflowButton::PaintBackground(gfx::Canvas* canvas, int alpha) { | 70 void OverflowButton::PaintBackground(gfx::Canvas* canvas, int alpha) { |
74 gfx::Rect bounds(GetContentsBounds()); | 71 gfx::Rect bounds(GetContentsBounds()); |
75 gfx::Rect rect(0, 0, kButtonHoverSize, kButtonHoverSize); | 72 gfx::Rect rect(0, 0, kButtonHoverSize, kButtonHoverSize); |
| 73 ShelfLayoutManager* shelf = |
| 74 ShelfLayoutManager::ForLauncher(GetWidget()->GetNativeView()); |
76 | 75 |
77 // Nudge the background a little to line up right. | 76 // Nudge the background a little to line up right. |
78 if (alignment_ == SHELF_ALIGNMENT_BOTTOM) { | 77 if (shelf->GetAlignment() == SHELF_ALIGNMENT_BOTTOM) { |
79 rect.set_origin(gfx::Point( | 78 rect.set_origin(gfx::Point( |
80 bounds.x() + ((bounds.width() - kButtonHoverSize) / 2) - 1, | 79 bounds.x() + ((bounds.width() - kButtonHoverSize) / 2) - 1, |
81 bounds.y() + kBackgroundOffset - 1)); | 80 bounds.y() + kBackgroundOffset - 1)); |
82 | 81 |
83 } else { | 82 } else { |
84 rect.set_origin(gfx::Point( | 83 rect.set_origin(gfx::Point( |
85 bounds.x() + kBackgroundOffset - 1, | 84 bounds.x() + kBackgroundOffset - 1, |
86 bounds.y() + ((bounds.height() - kButtonHoverSize) / 2) - 1)); | 85 bounds.y() + ((bounds.height() - kButtonHoverSize) / 2) - 1)); |
87 } | 86 } |
88 | 87 |
89 SkPaint paint; | 88 SkPaint paint; |
90 paint.setAntiAlias(true); | 89 paint.setAntiAlias(true); |
91 paint.setStyle(SkPaint::kFill_Style); | 90 paint.setStyle(SkPaint::kFill_Style); |
92 paint.setColor(SkColorSetARGB( | 91 paint.setColor(SkColorSetARGB( |
93 kButtonHoverAlpha * hover_animation_->GetCurrentValue(), | 92 kButtonHoverAlpha * hover_animation_->GetCurrentValue(), |
94 0, 0, 0)); | 93 0, 0, 0)); |
95 | 94 |
96 const SkScalar radius = SkIntToScalar(kButtonCornerRadius); | 95 const SkScalar radius = SkIntToScalar(kButtonCornerRadius); |
97 SkPath path; | 96 SkPath path; |
98 path.addRoundRect(gfx::RectToSkRect(rect), radius, radius); | 97 path.addRoundRect(gfx::RectToSkRect(rect), radius, radius); |
99 canvas->DrawPath(path, paint); | 98 canvas->DrawPath(path, paint); |
100 } | 99 } |
101 | 100 |
102 void OverflowButton::OnPaint(gfx::Canvas* canvas) { | 101 void OverflowButton::OnPaint(gfx::Canvas* canvas) { |
| 102 ShelfAlignment alignment = ShelfLayoutManager::ForLauncher( |
| 103 GetWidget()->GetNativeView())->GetAlignment(); |
| 104 |
103 if (hover_animation_->is_animating()) { | 105 if (hover_animation_->is_animating()) { |
104 PaintBackground( | 106 PaintBackground( |
105 canvas, | 107 canvas, |
106 kButtonHoverAlpha * hover_animation_->GetCurrentValue()); | 108 kButtonHoverAlpha * hover_animation_->GetCurrentValue()); |
107 } else if (state() == STATE_HOVERED || state() == STATE_PRESSED) { | 109 } else if (state() == STATE_HOVERED || state() == STATE_PRESSED) { |
108 PaintBackground(canvas, kButtonHoverAlpha); | 110 PaintBackground(canvas, kButtonHoverAlpha); |
109 } | 111 } |
110 | 112 |
111 if (height() < kButtonHoverSize) | 113 if (height() < kButtonHoverSize) |
112 return; | 114 return; |
113 | 115 |
114 gfx::Transform transform; | 116 gfx::Transform transform; |
115 | 117 |
116 switch (alignment_) { | 118 switch (alignment) { |
117 case SHELF_ALIGNMENT_BOTTOM: | 119 case SHELF_ALIGNMENT_BOTTOM: |
118 // Shift 1 pixel left to align with overflow bubble tip. | 120 // Shift 1 pixel left to align with overflow bubble tip. |
119 transform.Translate(-1, kBackgroundOffset); | 121 transform.Translate(-1, kBackgroundOffset); |
120 break; | 122 break; |
121 case SHELF_ALIGNMENT_LEFT: | 123 case SHELF_ALIGNMENT_LEFT: |
122 transform.Translate(kBackgroundOffset, -1); | 124 transform.Translate(kBackgroundOffset, -1); |
123 RotateClockwise(&transform); | 125 RotateClockwise(&transform); |
124 break; | 126 break; |
125 case SHELF_ALIGNMENT_RIGHT: | 127 case SHELF_ALIGNMENT_RIGHT: |
126 transform.Translate(kBackgroundOffset, height()); | 128 transform.Translate(kBackgroundOffset, height()); |
127 RotateCounterclockwise(&transform); | 129 RotateCounterclockwise(&transform); |
128 break; | 130 break; |
129 } | 131 } |
130 | 132 |
131 canvas->Save(); | 133 canvas->Save(); |
132 canvas->Transform(transform); | 134 canvas->Transform(transform); |
133 | 135 |
134 gfx::Rect rect(GetContentsBounds()); | 136 gfx::Rect rect(GetContentsBounds()); |
135 if (alignment_ == SHELF_ALIGNMENT_BOTTOM) { | 137 if (alignment == SHELF_ALIGNMENT_BOTTOM) { |
136 canvas->DrawImageInt(*image_, | 138 canvas->DrawImageInt(*image_, |
137 rect.x() + (rect.width() - image_->width()) / 2, | 139 rect.x() + (rect.width() - image_->width()) / 2, |
138 kButtonHoverSize - image_->height()); | 140 kButtonHoverSize - image_->height()); |
139 } else { | 141 } else { |
140 canvas->DrawImageInt(*image_, | 142 canvas->DrawImageInt(*image_, |
141 kButtonHoverSize - image_->width(), | 143 kButtonHoverSize - image_->width(), |
142 rect.y() + (rect.height() - image_->height()) / 2); | 144 rect.y() + (rect.height() - image_->height()) / 2); |
143 } | 145 } |
144 canvas->Restore(); | 146 canvas->Restore(); |
145 } | 147 } |
146 | 148 |
147 } // namespace internal | 149 } // namespace internal |
148 } // namespace ash | 150 } // namespace ash |
OLD | NEW |