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 "ui/views/window/frame_background.h" | 5 #include "ui/views/window/frame_background.h" |
6 | 6 |
7 #include "third_party/skia/include/core/SkCanvas.h" | 7 #include "third_party/skia/include/core/SkCanvas.h" |
8 #include "third_party/skia/include/core/SkColor.h" | 8 #include "third_party/skia/include/core/SkColor.h" |
9 #include "ui/base/theme_provider.h" | 9 #include "ui/base/theme_provider.h" |
10 #include "ui/gfx/canvas.h" | 10 #include "ui/gfx/canvas.h" |
11 #include "ui/native_theme/native_theme.h" | |
11 #include "ui/views/view.h" | 12 #include "ui/views/view.h" |
12 | 13 |
13 namespace views { | 14 namespace views { |
14 | 15 |
15 FrameBackground::FrameBackground() | 16 FrameBackground::FrameBackground() |
16 : frame_color_(0), | 17 : frame_color_(0), |
17 top_area_height_(0), | 18 top_area_height_(0), |
18 left_edge_(nullptr), | 19 left_edge_(nullptr), |
19 top_edge_(nullptr), | 20 top_edge_(nullptr), |
20 right_edge_(nullptr), | 21 right_edge_(nullptr), |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
118 } | 119 } |
119 | 120 |
120 void FrameBackground::PaintMaximized(gfx::Canvas* canvas, | 121 void FrameBackground::PaintMaximized(gfx::Canvas* canvas, |
121 const View* view) const { | 122 const View* view) const { |
122 // We will be painting from -|maximized_top_inset_| to | 123 // We will be painting from -|maximized_top_inset_| to |
123 // -|maximized_top_inset_| + |theme_image_|.height(). If this is less than | 124 // -|maximized_top_inset_| + |theme_image_|.height(). If this is less than |
124 // |top_area_height_|, we need to paint the frame color to fill in the area | 125 // |top_area_height_|, we need to paint the frame color to fill in the area |
125 // beneath the image. | 126 // beneath the image. |
126 int theme_frame_bottom = -maximized_top_inset_ + | 127 int theme_frame_bottom = -maximized_top_inset_ + |
127 (theme_image_.isNull() ? 0 : theme_image_.height()); | 128 (theme_image_.isNull() ? 0 : theme_image_.height()); |
128 if (top_area_height_ > theme_frame_bottom) { | 129 if (top_area_height_ > theme_frame_bottom) { |
sky
2017/01/11 21:54:52
no {}
Tom (Use chromium acct)
2017/01/11 22:44:48
Done.
| |
129 canvas->FillRect(gfx::Rect(0, 0, view->width(), top_area_height_), | 130 PaintFrameTopArea(canvas, view); |
130 frame_color_); | |
131 } | 131 } |
132 | 132 |
133 // Draw the theme frame. | 133 // Draw the theme frame. |
134 if (!theme_image_.isNull()) { | 134 if (!theme_image_.isNull()) { |
135 canvas->TileImageInt(theme_image_, 0, -maximized_top_inset_, view->width(), | 135 canvas->TileImageInt(theme_image_, 0, -maximized_top_inset_, view->width(), |
136 theme_image_.height()); | 136 theme_image_.height()); |
137 } | 137 } |
138 // Draw the theme frame overlay, if available. | 138 // Draw the theme frame overlay, if available. |
139 if (!theme_overlay_image_.isNull()) | 139 if (!theme_overlay_image_.isNull()) |
140 canvas->DrawImageInt(theme_overlay_image_, 0, -maximized_top_inset_); | 140 canvas->DrawImageInt(theme_overlay_image_, 0, -maximized_top_inset_); |
141 } | 141 } |
142 | 142 |
143 void FrameBackground::PaintFrameColor(gfx::Canvas* canvas, | 143 void FrameBackground::PaintFrameColor(gfx::Canvas* canvas, |
144 const View* view) const { | 144 const View* view) const { |
145 // Fill the top area. | 145 PaintFrameTopArea(canvas, view); |
146 canvas->FillRect(gfx::Rect(0, 0, view->width(), top_area_height_), | |
147 frame_color_); | |
148 | 146 |
149 // If the window is very short, we're done. | 147 // If the window is very short, we're done. |
150 int remaining_height = view->height() - top_area_height_; | 148 int remaining_height = view->height() - top_area_height_; |
151 if (remaining_height <= 0) | 149 if (remaining_height <= 0) |
152 return; | 150 return; |
153 | 151 |
154 // Fill down the sides. | 152 // Fill down the sides. |
155 canvas->FillRect(gfx::Rect(0, top_area_height_, left_edge_->width(), | 153 canvas->FillRect(gfx::Rect(0, top_area_height_, left_edge_->width(), |
156 remaining_height), frame_color_); | 154 remaining_height), frame_color_); |
157 canvas->FillRect(gfx::Rect(view->width() - right_edge_->width(), | 155 canvas->FillRect(gfx::Rect(view->width() - right_edge_->width(), |
158 top_area_height_, right_edge_->width(), | 156 top_area_height_, right_edge_->width(), |
159 remaining_height), frame_color_); | 157 remaining_height), frame_color_); |
160 | 158 |
161 // If the window is very narrow, we're done. | 159 // If the window is very narrow, we're done. |
162 int center_width = | 160 int center_width = |
163 view->width() - left_edge_->width() - right_edge_->width(); | 161 view->width() - left_edge_->width() - right_edge_->width(); |
164 if (center_width <= 0) | 162 if (center_width <= 0) |
165 return; | 163 return; |
166 | 164 |
167 // Fill the bottom area. | 165 // Fill the bottom area. |
168 canvas->FillRect(gfx::Rect(left_edge_->width(), | 166 canvas->FillRect(gfx::Rect(left_edge_->width(), |
169 view->height() - bottom_edge_->height(), | 167 view->height() - bottom_edge_->height(), |
170 center_width, bottom_edge_->height()), | 168 center_width, bottom_edge_->height()), |
171 frame_color_); | 169 frame_color_); |
172 } | 170 } |
173 | 171 |
172 void FrameBackground::PaintFrameTopArea(gfx::Canvas* canvas, | |
173 const View* view) const { | |
174 auto* native_theme = view->GetNativeTheme(); | |
175 ui::NativeTheme::ExtraParams params; | |
176 params.frame_top_area.is_active = is_active_; | |
177 params.frame_top_area.default_background_color = frame_color_; | |
178 native_theme->Paint(canvas->sk_canvas(), ui::NativeTheme::kFrameTopArea, | |
179 ui::NativeTheme::kNormal, | |
180 gfx::Rect(0, 0, view->width(), top_area_height_), params); | |
181 } | |
182 | |
174 } // namespace views | 183 } // namespace views |
OLD | NEW |