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

Side by Side Diff: ash/system/tray/tray_background_view.cc

Issue 798163003: Use nine image painter to draw tray background (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years 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/resources/ash_resources.grd ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 kGridSizeForPainter = 9;
121 const int kImages[kNumOrientations][kNumStates][kGridSizeForPainter] = {
122 { // Horizontal
123 IMAGE_GRID_HORIZONTAL(IDR_AURA_TRAY_BG_HORIZ),
124 IMAGE_GRID_HORIZONTAL(IDR_AURA_TRAY_BG_HORIZ_ONBLACK),
125 IMAGE_GRID_HORIZONTAL(IDR_AURA_TRAY_BG_HORIZ_PRESSED),
126 },
127 { // Vertical
128 IMAGE_GRID_VERTICAL(IDR_AURA_TRAY_BG_VERTICAL),
129 IMAGE_GRID_VERTICAL(IDR_AURA_TRAY_BG_VERTICAL_ONBLACK),
130 IMAGE_GRID_VERTICAL(IDR_AURA_TRAY_BG_VERTICAL_PRESSED),
131 }
132 };
133
166 int orientation = kImageHorizontal; 134 int orientation = kImageHorizontal;
167 ShelfWidget* shelf_widget = GetShelfWidget(); 135 ShelfWidget* shelf_widget = GetShelfWidget();
168 if (shelf_widget && 136 if (shelf_widget &&
169 !shelf_widget->shelf_layout_manager()->IsHorizontalAlignment()) 137 !shelf_widget->shelf_layout_manager()->IsHorizontalAlignment())
170 orientation = kImageVertical; 138 orientation = kImageVertical;
171 139
172 int state = kImageTypeDefault; 140 int state = kImageTypeDefault;
173 if (tray_background_view_->draw_background_as_active()) 141 if (tray_background_view_->draw_background_as_active())
174 state = kImageTypePressed; 142 state = kImageTypePressed;
175 else if (shelf_widget && shelf_widget->GetDimsShelf()) 143 else if (shelf_widget && shelf_widget->GetDimsShelf())
176 state = kImageTypeOnBlack; 144 state = kImageTypeOnBlack;
177 else 145 else
178 state = kImageTypeDefault; 146 state = kImageTypeDefault;
179 147
180 const gfx::ImageSkia* leading = leading_images_[orientation][state]; 148 ui::CreateNineImagePainter(kImages[orientation][state])
181 const gfx::ImageSkia* middle = middle_images_[orientation][state]; 149 ->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 } 150 }
220 151
221 SkColor color_; 152 SkColor color_;
222 // Reference to the TrayBackgroundView for which this is a background. 153 // Reference to the TrayBackgroundView for which this is a background.
223 TrayBackgroundView* tray_background_view_; 154 TrayBackgroundView* tray_background_view_;
224 155
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); 156 DISALLOW_COPY_AND_ASSIGN(TrayBackground);
232 }; 157 };
233 158
234 TrayBackgroundView::TrayContainer::TrayContainer(ShelfAlignment alignment) 159 TrayBackgroundView::TrayContainer::TrayContainer(ShelfAlignment alignment)
235 : alignment_(alignment) { 160 : alignment_(alignment) {
236 UpdateLayout(); 161 UpdateLayout();
237 } 162 }
238 163
239 void TrayBackgroundView::TrayContainer::SetAlignment(ShelfAlignment alignment) { 164 void TrayBackgroundView::TrayContainer::SetAlignment(ShelfAlignment alignment) {
240 if (alignment_ == alignment) 165 if (alignment_ == alignment)
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after
656 background_->set_alpha(kTrayBackgroundAlpha); 581 background_->set_alpha(kTrayBackgroundAlpha);
657 SchedulePaint(); 582 SchedulePaint();
658 } 583 }
659 584
660 void TrayBackgroundView::UpdateBubbleViewArrow( 585 void TrayBackgroundView::UpdateBubbleViewArrow(
661 views::TrayBubbleView* bubble_view) { 586 views::TrayBubbleView* bubble_view) {
662 // Nothing to do here. 587 // Nothing to do here.
663 } 588 }
664 589
665 } // namespace ash 590 } // namespace ash
OLDNEW
« no previous file with comments | « ash/resources/ash_resources.grd ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698