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), |
| 18 use_custom_frame_(true), |
| 19 is_active_(true), |
| 20 incognito_(false), |
17 top_area_height_(0), | 21 top_area_height_(0), |
18 left_edge_(nullptr), | 22 left_edge_(nullptr), |
19 top_edge_(nullptr), | 23 top_edge_(nullptr), |
20 right_edge_(nullptr), | 24 right_edge_(nullptr), |
21 bottom_edge_(nullptr), | 25 bottom_edge_(nullptr), |
22 top_left_corner_(nullptr), | 26 top_left_corner_(nullptr), |
23 top_right_corner_(nullptr), | 27 top_right_corner_(nullptr), |
24 bottom_left_corner_(nullptr), | 28 bottom_left_corner_(nullptr), |
25 bottom_right_corner_(nullptr), | 29 bottom_right_corner_(nullptr), |
26 maximized_top_inset_(0) {} | 30 maximized_top_inset_(0) {} |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 } | 122 } |
119 | 123 |
120 void FrameBackground::PaintMaximized(gfx::Canvas* canvas, | 124 void FrameBackground::PaintMaximized(gfx::Canvas* canvas, |
121 const View* view) const { | 125 const View* view) const { |
122 // We will be painting from -|maximized_top_inset_| to | 126 // We will be painting from -|maximized_top_inset_| to |
123 // -|maximized_top_inset_| + |theme_image_|.height(). If this is less than | 127 // -|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 | 128 // |top_area_height_|, we need to paint the frame color to fill in the area |
125 // beneath the image. | 129 // beneath the image. |
126 int theme_frame_bottom = -maximized_top_inset_ + | 130 int theme_frame_bottom = -maximized_top_inset_ + |
127 (theme_image_.isNull() ? 0 : theme_image_.height()); | 131 (theme_image_.isNull() ? 0 : theme_image_.height()); |
128 if (top_area_height_ > theme_frame_bottom) { | 132 if (top_area_height_ > theme_frame_bottom) |
129 canvas->FillRect(gfx::Rect(0, 0, view->width(), top_area_height_), | 133 PaintFrameTopArea(canvas, view); |
130 frame_color_); | |
131 } | |
132 | 134 |
133 // Draw the theme frame. | 135 // Draw the theme frame. |
134 if (!theme_image_.isNull()) { | 136 if (!theme_image_.isNull()) { |
135 canvas->TileImageInt(theme_image_, 0, -maximized_top_inset_, view->width(), | 137 canvas->TileImageInt(theme_image_, 0, -maximized_top_inset_, view->width(), |
136 theme_image_.height()); | 138 theme_image_.height()); |
137 } | 139 } |
138 // Draw the theme frame overlay, if available. | 140 // Draw the theme frame overlay, if available. |
139 if (!theme_overlay_image_.isNull()) | 141 if (!theme_overlay_image_.isNull()) |
140 canvas->DrawImageInt(theme_overlay_image_, 0, -maximized_top_inset_); | 142 canvas->DrawImageInt(theme_overlay_image_, 0, -maximized_top_inset_); |
141 } | 143 } |
142 | 144 |
143 void FrameBackground::PaintFrameColor(gfx::Canvas* canvas, | 145 void FrameBackground::PaintFrameColor(gfx::Canvas* canvas, |
144 const View* view) const { | 146 const View* view) const { |
145 // Fill the top area. | 147 PaintFrameTopArea(canvas, view); |
146 canvas->FillRect(gfx::Rect(0, 0, view->width(), top_area_height_), | |
147 frame_color_); | |
148 | 148 |
149 // If the window is very short, we're done. | 149 // If the window is very short, we're done. |
150 int remaining_height = view->height() - top_area_height_; | 150 int remaining_height = view->height() - top_area_height_; |
151 if (remaining_height <= 0) | 151 if (remaining_height <= 0) |
152 return; | 152 return; |
153 | 153 |
154 // Fill down the sides. | 154 // Fill down the sides. |
155 canvas->FillRect(gfx::Rect(0, top_area_height_, left_edge_->width(), | 155 canvas->FillRect(gfx::Rect(0, top_area_height_, left_edge_->width(), |
156 remaining_height), frame_color_); | 156 remaining_height), frame_color_); |
157 canvas->FillRect(gfx::Rect(view->width() - right_edge_->width(), | 157 canvas->FillRect(gfx::Rect(view->width() - right_edge_->width(), |
158 top_area_height_, right_edge_->width(), | 158 top_area_height_, right_edge_->width(), |
159 remaining_height), frame_color_); | 159 remaining_height), frame_color_); |
160 | 160 |
161 // If the window is very narrow, we're done. | 161 // If the window is very narrow, we're done. |
162 int center_width = | 162 int center_width = |
163 view->width() - left_edge_->width() - right_edge_->width(); | 163 view->width() - left_edge_->width() - right_edge_->width(); |
164 if (center_width <= 0) | 164 if (center_width <= 0) |
165 return; | 165 return; |
166 | 166 |
167 // Fill the bottom area. | 167 // Fill the bottom area. |
168 canvas->FillRect(gfx::Rect(left_edge_->width(), | 168 canvas->FillRect(gfx::Rect(left_edge_->width(), |
169 view->height() - bottom_edge_->height(), | 169 view->height() - bottom_edge_->height(), |
170 center_width, bottom_edge_->height()), | 170 center_width, bottom_edge_->height()), |
171 frame_color_); | 171 frame_color_); |
172 } | 172 } |
173 | 173 |
| 174 void FrameBackground::PaintFrameTopArea(gfx::Canvas* canvas, |
| 175 const View* view) const { |
| 176 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 177 auto* native_theme = view->GetNativeTheme(); |
| 178 ui::NativeTheme::ExtraParams params; |
| 179 params.frame_top_area.use_custom_frame = use_custom_frame_; |
| 180 params.frame_top_area.is_active = is_active_; |
| 181 params.frame_top_area.incognito = incognito_; |
| 182 params.frame_top_area.default_background_color = frame_color_; |
| 183 native_theme->Paint(canvas->sk_canvas(), ui::NativeTheme::kFrameTopArea, |
| 184 ui::NativeTheme::kNormal, |
| 185 gfx::Rect(0, 0, view->width(), top_area_height_), params); |
| 186 #else |
| 187 canvas->FillRect(gfx::Rect(0, 0, view->width(), top_area_height_), |
| 188 frame_color_); |
| 189 #endif |
| 190 } |
| 191 |
174 } // namespace views | 192 } // namespace views |
OLD | NEW |