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

Side by Side Diff: ui/views/window/frame_background.cc

Issue 8772060: Refactor window frame painting into a window background class (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: final cleanup of PaintRestored Created 9 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 | Annotate | Revision Log
« no previous file with comments | « ui/views/window/frame_background.h ('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
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ui/views/window/frame_background.h"
6
7 #include "grit/ui_resources.h"
8 #include "third_party/skia/include/core/SkCanvas.h"
9 #include "third_party/skia/include/core/SkColor.h"
10 #include "ui/base/theme_provider.h"
11 #include "ui/gfx/canvas.h"
12 #include "ui/views/view.h"
13
14 namespace views {
15
16 FrameBackground::FrameBackground()
17 : frame_color_(0),
18 theme_bitmap_(NULL),
19 theme_overlay_bitmap_(NULL),
20 top_area_height_(0),
21 left_edge_(NULL),
22 top_edge_(NULL),
23 right_edge_(NULL),
24 bottom_edge_(NULL),
25 top_left_corner_(NULL),
26 top_right_corner_(NULL),
27 bottom_left_corner_(NULL),
28 bottom_right_corner_(NULL),
29 maximized_top_left_(NULL),
30 maximized_top_right_(NULL),
31 maximized_top_offset_(0),
32 theme_background_y_(0) {
33 }
34
35 FrameBackground::~FrameBackground() {
36 }
37
38 void FrameBackground::SetSideImages(SkBitmap* left,
39 SkBitmap* top,
40 SkBitmap* right,
41 SkBitmap* bottom) {
42 left_edge_ = left;
43 top_edge_ = top;
44 right_edge_ = right;
45 bottom_edge_ = bottom;
46 }
47
48 void FrameBackground::SetCornerImages(SkBitmap* top_left,
49 SkBitmap* top_right,
50 SkBitmap* bottom_left,
51 SkBitmap* bottom_right) {
52 top_left_corner_ = top_left;
53 top_right_corner_ = top_right;
54 bottom_left_corner_ = bottom_left;
55 bottom_right_corner_ = bottom_right;
56 }
57
58 void FrameBackground::SetMaximizedCorners(SkBitmap* top_left,
59 SkBitmap* top_right,
60 int top_offset) {
61 maximized_top_left_ = top_left;
62 maximized_top_right_ = top_right;
63 maximized_top_offset_ = top_offset;
64 }
65
66 void FrameBackground::PaintRestored(gfx::Canvas* canvas, View* view) const {
67 // Fill with the frame color first so we have a constant background for
68 // areas not covered by the theme image.
69 PaintFrameColor(canvas, view);
70
71 // Draw the theme frame.
72 canvas->TileImageInt(*theme_bitmap_,
73 0, 0, view->width(), theme_bitmap_->height());
74
75 // Draw the theme frame overlay, if available.
76 if (theme_overlay_bitmap_)
77 canvas->DrawBitmapInt(*theme_overlay_bitmap_, 0, 0);
78
79 // Draw the top corners and edge, scaling the corner images down if they
80 // are too big and relative to the vertical space available.
81 int top_left_height =
82 std::min(top_left_corner_->height(),
83 view->height() - bottom_left_corner_->height());
84 canvas->DrawBitmapInt(*top_left_corner_,
85 0, 0, top_left_corner_->width(), top_left_height,
86 0, 0, top_left_corner_->width(), top_left_height,
87 false);
88 canvas->TileImageInt(*top_edge_,
89 top_left_corner_->width(),
90 0,
91 view->width() - top_left_corner_->width() - top_right_corner_->width(),
92 top_edge_->height());
93 int top_right_height =
94 std::min(top_right_corner_->height(),
95 view->height() - bottom_right_corner_->height());
96 canvas->DrawBitmapInt(*top_right_corner_,
97 0, 0,
98 top_right_corner_->width(), top_right_height,
99 view->width() - top_right_corner_->width(), 0,
100 top_right_corner_->width(), top_right_height,
101 false);
102
103 // Right edge.
104 int right_edge_height =
105 view->height() - top_right_height - bottom_right_corner_->height();
106 canvas->TileImageInt(*right_edge_,
107 view->width() - right_edge_->width(),
108 top_right_height,
109 right_edge_->width(),
110 right_edge_height);
111
112 // Bottom corners and edge.
113 canvas->DrawBitmapInt(*bottom_right_corner_,
114 view->width() - bottom_right_corner_->width(),
115 view->height() - bottom_right_corner_->height());
116 canvas->TileImageInt(
117 *bottom_edge_,
118 bottom_left_corner_->width(),
119 view->height() - bottom_edge_->height(),
120 view->width() - bottom_left_corner_->width()
121 - bottom_right_corner_->width(),
122 bottom_edge_->height());
123 canvas->DrawBitmapInt(*bottom_left_corner_, 0,
124 view->height() - bottom_left_corner_->height());
125
126 // Left edge.
127 int left_edge_height =
128 view->height() - top_left_height - bottom_left_corner_->height();
129 canvas->TileImageInt(*left_edge_,
130 0, top_left_height,
131 left_edge_->width(), left_edge_height);
132 }
133
134 void FrameBackground::PaintMaximized(gfx::Canvas* canvas, View* view) const {
135 // We will be painting from top_offset to top_offset + theme_frame_height. If
136 // this is less than top_area_height_, we need to paint the frame color
137 // to fill in the area beneath the image.
138 // TODO(jamescook): I'm not sure this is correct, as it doesn't seem to fully
139 // account for the top_offset, but this is how it worked before.
140 int theme_frame_bottom = maximized_top_offset_ + theme_bitmap_->height();
141 if (top_area_height_ > theme_frame_bottom) {
142 canvas->FillRect(frame_color_,
143 gfx::Rect(0, 0, view->width(), top_area_height_));
144 }
145
146 int left_offset = 0;
147 int right_offset = 0;
148
149 // Draw top-left and top-right corners to give maximized ChromeOS windows
150 // a rounded appearance.
151 if (maximized_top_left_ || maximized_top_right_) {
152 // If we have either a left or right we should have both.
153 DCHECK(maximized_top_left_ && maximized_top_right_);
154 left_offset = maximized_top_left_->width();
155 right_offset = maximized_top_right_->width();
156 canvas->DrawBitmapInt(*maximized_top_left_, 0, 0);
157 canvas->DrawBitmapInt(*maximized_top_right_,
158 view->width() - right_offset, 0);
159 }
160
161 // Draw the theme frame.
162 canvas->TileImageInt(*theme_bitmap_,
163 left_offset,
164 maximized_top_offset_,
165 view->width() - (left_offset + right_offset),
166 theme_bitmap_->height());
167 // Draw the theme frame overlay, if available.
168 if (theme_overlay_bitmap_)
169 canvas->DrawBitmapInt(*theme_overlay_bitmap_, 0, theme_background_y_);
170 }
171
172 void FrameBackground::PaintFrameColor(gfx::Canvas* canvas, View* view) const {
173 // Fill the top area.
174 canvas->FillRect(frame_color_,
175 gfx::Rect(0, 0, view->width(), top_area_height_));
176
177 // If the window is very short, we're done.
178 int remaining_height = view->height() - top_area_height_;
179 if (remaining_height <= 0)
180 return;
181
182 // Fill down the sides.
183 canvas->FillRect(frame_color_,
184 gfx::Rect(0, top_area_height_,
185 left_edge_->width(), remaining_height));
186 canvas->FillRect(frame_color_,
187 gfx::Rect(view->width() - right_edge_->width(),
188 top_area_height_,
189 right_edge_->width(),
190 remaining_height));
191
192 // If the window is very narrow, we're done.
193 int center_width =
194 view->width() - left_edge_->width() - right_edge_->width();
195 if (center_width <= 0)
196 return;
197
198 // Fill the bottom area.
199 canvas->FillRect(frame_color_,
200 gfx::Rect(left_edge_->width(),
201 view->height() - bottom_edge_->height(),
202 center_width,
203 bottom_edge_->height()));
204 }
205
206 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/window/frame_background.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698