OLD | NEW |
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2016 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 "chrome/browser/ui/views/frame/windows_10_caption_button.h" | 5 #include "chrome/browser/ui/views/frame/windows_10_caption_button.h" |
6 | 6 |
7 #include "chrome/browser/themes/theme_properties.h" | 7 #include "chrome/browser/themes/theme_properties.h" |
8 #include "chrome/browser/ui/views/frame/browser_view.h" | 8 #include "chrome/browser/ui/views/frame/browser_view.h" |
9 #include "chrome/browser/ui/views/frame/glass_browser_frame_view.h" | 9 #include "chrome/browser/ui/views/frame/glass_browser_frame_view.h" |
10 #include "chrome/grit/theme_resources.h" | 10 #include "chrome/grit/theme_resources.h" |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 SK_AlphaTRANSPARENT, hovered_alpha); | 108 SK_AlphaTRANSPARENT, hovered_alpha); |
109 canvas->FillRect(GetContentsBounds(), SkColorSetA(base_color, alpha)); | 109 canvas->FillRect(GetContentsBounds(), SkColorSetA(base_color, alpha)); |
110 } | 110 } |
111 | 111 |
112 namespace { | 112 namespace { |
113 | 113 |
114 // Canvas::DrawRect's stroke can bleed out of |rect|'s bounds, so this draws a | 114 // Canvas::DrawRect's stroke can bleed out of |rect|'s bounds, so this draws a |
115 // rectangle inset such that the result is constrained to |rect|'s size. | 115 // rectangle inset such that the result is constrained to |rect|'s size. |
116 void DrawRect(gfx::Canvas* canvas, | 116 void DrawRect(gfx::Canvas* canvas, |
117 const gfx::Rect& rect, | 117 const gfx::Rect& rect, |
118 const SkPaint& paint) { | 118 const cc::PaintFlags& flags) { |
119 gfx::RectF rect_f(rect); | 119 gfx::RectF rect_f(rect); |
120 float stroke_half_width = paint.getStrokeWidth() / 2; | 120 float stroke_half_width = flags.getStrokeWidth() / 2; |
121 rect_f.Inset(stroke_half_width, stroke_half_width); | 121 rect_f.Inset(stroke_half_width, stroke_half_width); |
122 canvas->DrawRect(rect_f, paint); | 122 canvas->DrawRect(rect_f, flags); |
123 } | 123 } |
124 | 124 |
125 } // namespace | 125 } // namespace |
126 | 126 |
127 void Windows10CaptionButton::PaintSymbol(gfx::Canvas* canvas) { | 127 void Windows10CaptionButton::PaintSymbol(gfx::Canvas* canvas) { |
128 SkColor symbol_color = GetBaseColor(); | 128 SkColor symbol_color = GetBaseColor(); |
129 if (!frame_view_->ShouldPaintAsActive() && state() != STATE_HOVERED && | 129 if (!frame_view_->ShouldPaintAsActive() && state() != STATE_HOVERED && |
130 state() != STATE_PRESSED) { | 130 state() != STATE_PRESSED) { |
131 symbol_color = SkColorSetA(symbol_color, 0x65); | 131 symbol_color = SkColorSetA(symbol_color, 0x65); |
132 } else if (button_type_ == VIEW_ID_CLOSE_BUTTON && | 132 } else if (button_type_ == VIEW_ID_CLOSE_BUTTON && |
133 hover_animation().is_animating()) { | 133 hover_animation().is_animating()) { |
134 symbol_color = gfx::Tween::ColorValueBetween( | 134 symbol_color = gfx::Tween::ColorValueBetween( |
135 hover_animation().GetCurrentValue(), symbol_color, SK_ColorWHITE); | 135 hover_animation().GetCurrentValue(), symbol_color, SK_ColorWHITE); |
136 } else if (button_type_ == VIEW_ID_CLOSE_BUTTON && | 136 } else if (button_type_ == VIEW_ID_CLOSE_BUTTON && |
137 (state() == STATE_HOVERED || state() == STATE_PRESSED)) { | 137 (state() == STATE_HOVERED || state() == STATE_PRESSED)) { |
138 symbol_color = SK_ColorWHITE; | 138 symbol_color = SK_ColorWHITE; |
139 } | 139 } |
140 | 140 |
141 gfx::ScopedCanvas scoped_canvas(canvas); | 141 gfx::ScopedCanvas scoped_canvas(canvas); |
142 const float scale = canvas->UndoDeviceScaleFactor(); | 142 const float scale = canvas->UndoDeviceScaleFactor(); |
143 | 143 |
144 const int symbol_size_pixels = std::round(10 * scale); | 144 const int symbol_size_pixels = std::round(10 * scale); |
145 gfx::RectF bounds_rect(GetContentsBounds()); | 145 gfx::RectF bounds_rect(GetContentsBounds()); |
146 bounds_rect.Scale(scale); | 146 bounds_rect.Scale(scale); |
147 gfx::Rect symbol_rect(gfx::ToEnclosingRect(bounds_rect)); | 147 gfx::Rect symbol_rect(gfx::ToEnclosingRect(bounds_rect)); |
148 symbol_rect.ClampToCenteredSize( | 148 symbol_rect.ClampToCenteredSize( |
149 gfx::Size(symbol_size_pixels, symbol_size_pixels)); | 149 gfx::Size(symbol_size_pixels, symbol_size_pixels)); |
150 | 150 |
151 SkPaint paint; | 151 cc::PaintFlags flags; |
152 paint.setAntiAlias(false); | 152 flags.setAntiAlias(false); |
153 paint.setColor(symbol_color); | 153 flags.setColor(symbol_color); |
154 paint.setStyle(SkPaint::kStroke_Style); | 154 flags.setStyle(cc::PaintFlags::kStroke_Style); |
155 // Stroke width jumps up a pixel every time we reach a new integral scale. | 155 // Stroke width jumps up a pixel every time we reach a new integral scale. |
156 const int stroke_width = std::floor(scale); | 156 const int stroke_width = std::floor(scale); |
157 paint.setStrokeWidth(stroke_width); | 157 flags.setStrokeWidth(stroke_width); |
158 | 158 |
159 switch (button_type_) { | 159 switch (button_type_) { |
160 case VIEW_ID_MINIMIZE_BUTTON: { | 160 case VIEW_ID_MINIMIZE_BUTTON: { |
161 const int y = symbol_rect.CenterPoint().y(); | 161 const int y = symbol_rect.CenterPoint().y(); |
162 const gfx::Point p1 = gfx::Point(symbol_rect.x(), y); | 162 const gfx::Point p1 = gfx::Point(symbol_rect.x(), y); |
163 const gfx::Point p2 = gfx::Point(symbol_rect.right(), y); | 163 const gfx::Point p2 = gfx::Point(symbol_rect.right(), y); |
164 canvas->DrawLine(p1, p2, paint); | 164 canvas->DrawLine(p1, p2, flags); |
165 return; | 165 return; |
166 } | 166 } |
167 | 167 |
168 case VIEW_ID_MAXIMIZE_BUTTON: | 168 case VIEW_ID_MAXIMIZE_BUTTON: |
169 DrawRect(canvas, symbol_rect, paint); | 169 DrawRect(canvas, symbol_rect, flags); |
170 return; | 170 return; |
171 | 171 |
172 case VIEW_ID_RESTORE_BUTTON: { | 172 case VIEW_ID_RESTORE_BUTTON: { |
173 // Bottom left ("in front") square. | 173 // Bottom left ("in front") square. |
174 const int separation = std::floor(2 * scale); | 174 const int separation = std::floor(2 * scale); |
175 symbol_rect.Inset(0, separation, separation, 0); | 175 symbol_rect.Inset(0, separation, separation, 0); |
176 DrawRect(canvas, symbol_rect, paint); | 176 DrawRect(canvas, symbol_rect, flags); |
177 | 177 |
178 // Top right ("behind") square. | 178 // Top right ("behind") square. |
179 canvas->ClipRect(symbol_rect, SkClipOp::kDifference); | 179 canvas->ClipRect(symbol_rect, SkClipOp::kDifference); |
180 symbol_rect.Offset(separation, -separation); | 180 symbol_rect.Offset(separation, -separation); |
181 DrawRect(canvas, symbol_rect, paint); | 181 DrawRect(canvas, symbol_rect, flags); |
182 return; | 182 return; |
183 } | 183 } |
184 | 184 |
185 case VIEW_ID_CLOSE_BUTTON: { | 185 case VIEW_ID_CLOSE_BUTTON: { |
186 paint.setAntiAlias(true); | 186 flags.setAntiAlias(true); |
187 // The close button's X is surrounded by a "halo" of transparent pixels. | 187 // The close button's X is surrounded by a "halo" of transparent pixels. |
188 // When the X is white, the transparent pixels need to be a bit brighter | 188 // When the X is white, the transparent pixels need to be a bit brighter |
189 // to be visible. | 189 // to be visible. |
190 const float stroke_halo = | 190 const float stroke_halo = |
191 stroke_width * (symbol_color == SK_ColorWHITE ? 0.1f : 0.05f); | 191 stroke_width * (symbol_color == SK_ColorWHITE ? 0.1f : 0.05f); |
192 paint.setStrokeWidth(stroke_width + stroke_halo); | 192 flags.setStrokeWidth(stroke_width + stroke_halo); |
193 | 193 |
194 // TODO(bsep): This sometimes draws misaligned at fractional device scales | 194 // TODO(bsep): This sometimes draws misaligned at fractional device scales |
195 // because the button's origin isn't necessarily aligned to pixels. | 195 // because the button's origin isn't necessarily aligned to pixels. |
196 canvas->ClipRect(symbol_rect); | 196 canvas->ClipRect(symbol_rect); |
197 SkPath path; | 197 SkPath path; |
198 path.moveTo(symbol_rect.x(), symbol_rect.y()); | 198 path.moveTo(symbol_rect.x(), symbol_rect.y()); |
199 path.lineTo(symbol_rect.right(), symbol_rect.bottom()); | 199 path.lineTo(symbol_rect.right(), symbol_rect.bottom()); |
200 path.moveTo(symbol_rect.right(), symbol_rect.y()); | 200 path.moveTo(symbol_rect.right(), symbol_rect.y()); |
201 path.lineTo(symbol_rect.x(), symbol_rect.bottom()); | 201 path.lineTo(symbol_rect.x(), symbol_rect.bottom()); |
202 canvas->DrawPath(path, paint); | 202 canvas->DrawPath(path, flags); |
203 return; | 203 return; |
204 } | 204 } |
205 | 205 |
206 default: | 206 default: |
207 NOTREACHED(); | 207 NOTREACHED(); |
208 return; | 208 return; |
209 } | 209 } |
210 } | 210 } |
OLD | NEW |