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/system/tray/tray_background_view.h" | 5 #include "ash/system/tray/tray_background_view.h" |
6 | 6 |
7 #include "ash/root_window_controller.h" | 7 #include "ash/root_window_controller.h" |
8 #include "ash/screen_util.h" | 8 #include "ash/screen_util.h" |
9 #include "ash/shelf/shelf_layout_manager.h" | 9 #include "ash/shelf/shelf_layout_manager.h" |
10 #include "ash/shelf/shelf_widget.h" | 10 #include "ash/shelf/shelf_widget.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/system/status_area_widget.h" | 13 #include "ash/system/status_area_widget.h" |
14 #include "ash/system/status_area_widget_delegate.h" | 14 #include "ash/system/status_area_widget_delegate.h" |
15 #include "ash/system/tray/system_tray.h" | 15 #include "ash/system/tray/system_tray.h" |
16 #include "ash/system/tray/tray_constants.h" | 16 #include "ash/system/tray/tray_constants.h" |
17 #include "ash/system/tray/tray_event_filter.h" | 17 #include "ash/system/tray/tray_event_filter.h" |
18 #include "ash/wm/window_animations.h" | 18 #include "ash/wm/window_animations.h" |
19 #include "base/command_line.h" | 19 #include "base/command_line.h" |
20 #include "grit/ash_resources.h" | 20 #include "grit/ash_resources.h" |
21 #include "ui/accessibility/ax_view_state.h" | 21 #include "ui/accessibility/ax_view_state.h" |
22 #include "ui/aura/window.h" | 22 #include "ui/aura/window.h" |
23 #include "ui/aura/window_event_dispatcher.h" | 23 #include "ui/aura/window_event_dispatcher.h" |
24 #include "ui/base/resource/resource_bundle.h" | 24 #include "ui/base/nine_image_painter_factory.h" |
25 #include "ui/base/ui_base_switches_util.h" | 25 #include "ui/base/ui_base_switches_util.h" |
26 #include "ui/compositor/layer.h" | 26 #include "ui/compositor/layer.h" |
27 #include "ui/compositor/layer_animation_element.h" | 27 #include "ui/compositor/layer_animation_element.h" |
28 #include "ui/compositor/scoped_layer_animation_settings.h" | 28 #include "ui/compositor/scoped_layer_animation_settings.h" |
29 #include "ui/events/event_constants.h" | 29 #include "ui/events/event_constants.h" |
30 #include "ui/gfx/animation/tween.h" | 30 #include "ui/gfx/animation/tween.h" |
31 #include "ui/gfx/canvas.h" | 31 #include "ui/gfx/canvas.h" |
32 #include "ui/gfx/image/image_skia.h" | 32 #include "ui/gfx/image/image_skia.h" |
33 #include "ui/gfx/image/image_skia_operations.h" | 33 #include "ui/gfx/image/image_skia_operations.h" |
34 #include "ui/gfx/nine_image_painter.h" | |
34 #include "ui/gfx/rect.h" | 35 #include "ui/gfx/rect.h" |
35 #include "ui/gfx/screen.h" | 36 #include "ui/gfx/screen.h" |
36 #include "ui/gfx/skia_util.h" | 37 #include "ui/gfx/skia_util.h" |
37 #include "ui/gfx/transform.h" | 38 #include "ui/gfx/transform.h" |
38 #include "ui/views/background.h" | 39 #include "ui/views/background.h" |
39 #include "ui/views/layout/box_layout.h" | 40 #include "ui/views/layout/box_layout.h" |
40 | 41 |
41 namespace { | 42 namespace { |
42 | 43 |
43 const int kTrayBackgroundAlpha = 100; | 44 const int kTrayBackgroundAlpha = 100; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
93 const static int kImageTypePressed = 2; | 94 const static int kImageTypePressed = 2; |
94 const static int kNumStates = 3; | 95 const static int kNumStates = 3; |
95 | 96 |
96 const static int kImageHorizontal = 0; | 97 const static int kImageHorizontal = 0; |
97 const static int kImageVertical = 1; | 98 const static int kImageVertical = 1; |
98 const static int kNumOrientations = 2; | 99 const static int kNumOrientations = 2; |
99 | 100 |
100 explicit TrayBackground(TrayBackgroundView* tray_background_view) : | 101 explicit TrayBackground(TrayBackgroundView* tray_background_view) : |
101 tray_background_view_(tray_background_view) { | 102 tray_background_view_(tray_background_view) { |
102 set_alpha(kTrayBackgroundAlpha); | 103 set_alpha(kTrayBackgroundAlpha); |
103 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | |
104 leading_images_[kImageHorizontal][kImageTypeDefault] = | |
105 rb.GetImageNamed(IDR_AURA_TRAY_BG_HORIZ_LEFT).ToImageSkia(); | |
106 middle_images_[kImageHorizontal][kImageTypeDefault] = | |
107 rb.GetImageNamed(IDR_AURA_TRAY_BG_HORIZ_CENTER).ToImageSkia(); | |
108 trailing_images_[kImageHorizontal][kImageTypeDefault] = | |
109 rb.GetImageNamed(IDR_AURA_TRAY_BG_HORIZ_RIGHT).ToImageSkia(); | |
110 | |
111 leading_images_[kImageHorizontal][kImageTypeOnBlack] = | |
112 rb.GetImageNamed(IDR_AURA_TRAY_BG_HORIZ_LEFT_ONBLACK).ToImageSkia(); | |
113 middle_images_[kImageHorizontal][kImageTypeOnBlack] = | |
114 rb.GetImageNamed(IDR_AURA_TRAY_BG_HORIZ_CENTER_ONBLACK).ToImageSkia(); | |
115 trailing_images_[kImageHorizontal][kImageTypeOnBlack] = | |
116 rb.GetImageNamed(IDR_AURA_TRAY_BG_HORIZ_RIGHT_ONBLACK).ToImageSkia(); | |
117 | |
118 leading_images_[kImageHorizontal][kImageTypePressed] = | |
119 rb.GetImageNamed(IDR_AURA_TRAY_BG_HORIZ_LEFT_PRESSED).ToImageSkia(); | |
120 middle_images_[kImageHorizontal][kImageTypePressed] = | |
121 rb.GetImageNamed(IDR_AURA_TRAY_BG_HORIZ_CENTER_PRESSED).ToImageSkia(); | |
122 trailing_images_[kImageHorizontal][kImageTypePressed] = | |
123 rb.GetImageNamed(IDR_AURA_TRAY_BG_HORIZ_RIGHT_PRESSED).ToImageSkia(); | |
124 | |
125 leading_images_[kImageVertical][kImageTypeDefault] = | |
126 rb.GetImageNamed(IDR_AURA_TRAY_BG_VERTICAL_TOP).ToImageSkia(); | |
127 middle_images_[kImageVertical][kImageTypeDefault] = | |
128 rb.GetImageNamed( | |
129 IDR_AURA_TRAY_BG_VERTICAL_CENTER).ToImageSkia(); | |
130 trailing_images_[kImageVertical][kImageTypeDefault] = | |
131 rb.GetImageNamed(IDR_AURA_TRAY_BG_VERTICAL_BOTTOM).ToImageSkia(); | |
132 | |
133 leading_images_[kImageVertical][kImageTypeOnBlack] = | |
134 rb.GetImageNamed(IDR_AURA_TRAY_BG_VERTICAL_TOP_ONBLACK).ToImageSkia(); | |
135 middle_images_[kImageVertical][kImageTypeOnBlack] = | |
136 rb.GetImageNamed( | |
137 IDR_AURA_TRAY_BG_VERTICAL_CENTER_ONBLACK).ToImageSkia(); | |
138 trailing_images_[kImageVertical][kImageTypeOnBlack] = | |
139 rb.GetImageNamed( | |
140 IDR_AURA_TRAY_BG_VERTICAL_BOTTOM_ONBLACK).ToImageSkia(); | |
141 | |
142 leading_images_[kImageVertical][kImageTypePressed] = | |
143 rb.GetImageNamed(IDR_AURA_TRAY_BG_VERTICAL_TOP_PRESSED).ToImageSkia(); | |
144 middle_images_[kImageVertical][kImageTypePressed] = | |
145 rb.GetImageNamed( | |
146 IDR_AURA_TRAY_BG_VERTICAL_CENTER_PRESSED).ToImageSkia(); | |
147 trailing_images_[kImageVertical][kImageTypePressed] = | |
148 rb.GetImageNamed( | |
149 IDR_AURA_TRAY_BG_VERTICAL_BOTTOM_PRESSED).ToImageSkia(); | |
150 } | 104 } |
151 | 105 |
152 ~TrayBackground() override {} | 106 ~TrayBackground() override {} |
153 | 107 |
154 SkColor color() { return color_; } | 108 SkColor color() { return color_; } |
155 void set_color(SkColor color) { color_ = color; } | 109 void set_color(SkColor color) { color_ = color; } |
156 void set_alpha(int alpha) { color_ = SkColorSetARGB(alpha, 0, 0, 0); } | 110 void set_alpha(int alpha) { color_ = SkColorSetARGB(alpha, 0, 0, 0); } |
157 | 111 |
158 private: | 112 private: |
159 ShelfWidget* GetShelfWidget() const { | 113 ShelfWidget* GetShelfWidget() const { |
160 return RootWindowController::ForWindow(tray_background_view_-> | 114 return RootWindowController::ForWindow(tray_background_view_-> |
161 status_area_widget()->GetNativeWindow())->shelf(); | 115 status_area_widget()->GetNativeWindow())->shelf(); |
162 } | 116 } |
163 | 117 |
164 // Overridden from views::Background. | 118 // Overridden from views::Background. |
165 void Paint(gfx::Canvas* canvas, views::View* view) const override { | 119 void Paint(gfx::Canvas* canvas, views::View* view) const override { |
120 const int kImages[kNumOrientations][kNumStates][9] = { | |
stevenjb
2014/12/15 17:19:10
nit: 9 should be a const defined with the macro, o
sadrul
2014/12/15 19:45:56
Someone using a NineImagePainter should be aware o
stevenjb
2014/12/15 20:03:23
Just saying that, even with the diff right here in
sadrul
2014/12/15 20:55:41
Consider the alternative: we would have a constant
| |
121 { // Horizontal | |
122 IMAGE_GRID_HORIZONTAL(IDR_AURA_TRAY_BG_HORIZ), | |
123 IMAGE_GRID_HORIZONTAL(IDR_AURA_TRAY_BG_HORIZ_ONBLACK), | |
124 IMAGE_GRID_HORIZONTAL(IDR_AURA_TRAY_BG_HORIZ_PRESSED), | |
125 }, | |
126 { // Vertical | |
127 IMAGE_GRID_VERTICAL(IDR_AURA_TRAY_BG_VERTICAL), | |
128 IMAGE_GRID_VERTICAL(IDR_AURA_TRAY_BG_VERTICAL_ONBLACK), | |
129 IMAGE_GRID_VERTICAL(IDR_AURA_TRAY_BG_VERTICAL_PRESSED), | |
130 } | |
131 }; | |
132 | |
166 int orientation = kImageHorizontal; | 133 int orientation = kImageHorizontal; |
167 ShelfWidget* shelf_widget = GetShelfWidget(); | 134 ShelfWidget* shelf_widget = GetShelfWidget(); |
168 if (shelf_widget && | 135 if (shelf_widget && |
169 !shelf_widget->shelf_layout_manager()->IsHorizontalAlignment()) | 136 !shelf_widget->shelf_layout_manager()->IsHorizontalAlignment()) |
170 orientation = kImageVertical; | 137 orientation = kImageVertical; |
171 | 138 |
172 int state = kImageTypeDefault; | 139 int state = kImageTypeDefault; |
173 if (tray_background_view_->draw_background_as_active()) | 140 if (tray_background_view_->draw_background_as_active()) |
174 state = kImageTypePressed; | 141 state = kImageTypePressed; |
175 else if (shelf_widget && shelf_widget->GetDimsShelf()) | 142 else if (shelf_widget && shelf_widget->GetDimsShelf()) |
176 state = kImageTypeOnBlack; | 143 state = kImageTypeOnBlack; |
177 else | 144 else |
178 state = kImageTypeDefault; | 145 state = kImageTypeDefault; |
179 | 146 |
180 const gfx::ImageSkia* leading = leading_images_[orientation][state]; | 147 ui::CreateNineImagePainter(kImages[orientation][state]) |
181 const gfx::ImageSkia* middle = middle_images_[orientation][state]; | 148 ->Paint(canvas, view->GetLocalBounds()); |
182 const gfx::ImageSkia* trailing = trailing_images_[orientation][state]; | |
183 | |
184 gfx::Rect bounds(view->GetLocalBounds()); | |
185 gfx::Point leading_location, trailing_location; | |
186 gfx::Rect middle_bounds; | |
187 | |
188 if (orientation == kImageHorizontal) { | |
189 leading_location = gfx::Point(0, 0); | |
190 trailing_location = gfx::Point(bounds.width() - trailing->width(), 0); | |
191 middle_bounds = gfx::Rect( | |
192 leading->width(), | |
193 0, | |
194 bounds.width() - (leading->width() + trailing->width()), | |
195 bounds.height()); | |
196 } else { | |
197 leading_location = gfx::Point(0, 0); | |
198 trailing_location = gfx::Point(0, bounds.height() - trailing->height()); | |
199 middle_bounds = gfx::Rect( | |
200 0, | |
201 leading->height(), | |
202 bounds.width(), | |
203 bounds.height() - (leading->height() + trailing->height())); | |
204 } | |
205 | |
206 canvas->DrawImageInt(*leading, | |
207 leading_location.x(), | |
208 leading_location.y()); | |
209 | |
210 canvas->DrawImageInt(*trailing, | |
211 trailing_location.x(), | |
212 trailing_location.y()); | |
213 | |
214 canvas->TileImageInt(*middle, | |
215 middle_bounds.x(), | |
216 middle_bounds.y(), | |
217 middle_bounds.width(), | |
218 middle_bounds.height()); | |
219 } | 149 } |
220 | 150 |
221 SkColor color_; | 151 SkColor color_; |
222 // Reference to the TrayBackgroundView for which this is a background. | 152 // Reference to the TrayBackgroundView for which this is a background. |
223 TrayBackgroundView* tray_background_view_; | 153 TrayBackgroundView* tray_background_view_; |
224 | 154 |
225 // References to the images used as backgrounds, they are owned by the | |
226 // resource bundle class. | |
227 const gfx::ImageSkia* leading_images_[kNumOrientations][kNumStates]; | |
228 const gfx::ImageSkia* middle_images_[kNumOrientations][kNumStates]; | |
229 const gfx::ImageSkia* trailing_images_[kNumOrientations][kNumStates]; | |
230 | |
231 DISALLOW_COPY_AND_ASSIGN(TrayBackground); | 155 DISALLOW_COPY_AND_ASSIGN(TrayBackground); |
232 }; | 156 }; |
233 | 157 |
234 TrayBackgroundView::TrayContainer::TrayContainer(ShelfAlignment alignment) | 158 TrayBackgroundView::TrayContainer::TrayContainer(ShelfAlignment alignment) |
235 : alignment_(alignment) { | 159 : alignment_(alignment) { |
236 UpdateLayout(); | 160 UpdateLayout(); |
237 } | 161 } |
238 | 162 |
239 void TrayBackgroundView::TrayContainer::SetAlignment(ShelfAlignment alignment) { | 163 void TrayBackgroundView::TrayContainer::SetAlignment(ShelfAlignment alignment) { |
240 if (alignment_ == alignment) | 164 if (alignment_ == alignment) |
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
656 background_->set_alpha(kTrayBackgroundAlpha); | 580 background_->set_alpha(kTrayBackgroundAlpha); |
657 SchedulePaint(); | 581 SchedulePaint(); |
658 } | 582 } |
659 | 583 |
660 void TrayBackgroundView::UpdateBubbleViewArrow( | 584 void TrayBackgroundView::UpdateBubbleViewArrow( |
661 views::TrayBubbleView* bubble_view) { | 585 views::TrayBubbleView* bubble_view) { |
662 // Nothing to do here. | 586 // Nothing to do here. |
663 } | 587 } |
664 | 588 |
665 } // namespace ash | 589 } // namespace ash |
OLD | NEW |