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/color_chooser/color_chooser_view.h" | 5 #include "ui/views/color_chooser/color_chooser_view.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 public: | 119 public: |
120 explicit HueView(ColorChooserView* chooser_view); | 120 explicit HueView(ColorChooserView* chooser_view); |
121 | 121 |
122 void OnHueChanged(SkScalar hue); | 122 void OnHueChanged(SkScalar hue); |
123 | 123 |
124 private: | 124 private: |
125 // LocatedEventHandlerView overrides: | 125 // LocatedEventHandlerView overrides: |
126 virtual void ProcessEventAtLocation(const gfx::Point& point) OVERRIDE; | 126 virtual void ProcessEventAtLocation(const gfx::Point& point) OVERRIDE; |
127 | 127 |
128 // View overrides: | 128 // View overrides: |
129 virtual gfx::Size GetPreferredSize() OVERRIDE; | 129 virtual gfx::Size GetPreferredSize() const OVERRIDE; |
130 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; | 130 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; |
131 | 131 |
132 ColorChooserView* chooser_view_; | 132 ColorChooserView* chooser_view_; |
133 int level_; | 133 int level_; |
134 | 134 |
135 DISALLOW_COPY_AND_ASSIGN(HueView); | 135 DISALLOW_COPY_AND_ASSIGN(HueView); |
136 }; | 136 }; |
137 | 137 |
138 ColorChooserView::HueView::HueView(ColorChooserView* chooser_view) | 138 ColorChooserView::HueView::HueView(ColorChooserView* chooser_view) |
139 : chooser_view_(chooser_view), | 139 : chooser_view_(chooser_view), |
(...skipping 17 matching lines...) Expand all Loading... |
157 level_ = std::max(kBorderWidth, | 157 level_ = std::max(kBorderWidth, |
158 std::min(height() - 1 - kBorderWidth, point.y())); | 158 std::min(height() - 1 - kBorderWidth, point.y())); |
159 int base_height = kSaturationValueSize - 1; | 159 int base_height = kSaturationValueSize - 1; |
160 chooser_view_->OnHueChosen(SkScalarDiv( | 160 chooser_view_->OnHueChosen(SkScalarDiv( |
161 SkScalarMul(SkIntToScalar(360), | 161 SkScalarMul(SkIntToScalar(360), |
162 SkIntToScalar(base_height - (level_ - kBorderWidth))), | 162 SkIntToScalar(base_height - (level_ - kBorderWidth))), |
163 SkIntToScalar(base_height))); | 163 SkIntToScalar(base_height))); |
164 SchedulePaint(); | 164 SchedulePaint(); |
165 } | 165 } |
166 | 166 |
167 gfx::Size ColorChooserView::HueView::GetPreferredSize() { | 167 gfx::Size ColorChooserView::HueView::GetPreferredSize() const { |
168 // We put indicators on the both sides of the hue bar. | 168 // We put indicators on the both sides of the hue bar. |
169 return gfx::Size(kHueBarWidth + kHueIndicatorSize * 2 + kBorderWidth * 2, | 169 return gfx::Size(kHueBarWidth + kHueIndicatorSize * 2 + kBorderWidth * 2, |
170 kSaturationValueSize + kBorderWidth * 2); | 170 kSaturationValueSize + kBorderWidth * 2); |
171 } | 171 } |
172 | 172 |
173 void ColorChooserView::HueView::OnPaint(gfx::Canvas* canvas) { | 173 void ColorChooserView::HueView::OnPaint(gfx::Canvas* canvas) { |
174 SkScalar hsv[3]; | 174 SkScalar hsv[3]; |
175 // In the hue bar, saturation and value for the color should be always 100%. | 175 // In the hue bar, saturation and value for the color should be always 100%. |
176 hsv[1] = SK_Scalar1; | 176 hsv[1] = SK_Scalar1; |
177 hsv[2] = SK_Scalar1; | 177 hsv[2] = SK_Scalar1; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 explicit SaturationValueView(ColorChooserView* chooser_view); | 231 explicit SaturationValueView(ColorChooserView* chooser_view); |
232 | 232 |
233 void OnHueChanged(SkScalar hue); | 233 void OnHueChanged(SkScalar hue); |
234 void OnSaturationValueChanged(SkScalar saturation, SkScalar value); | 234 void OnSaturationValueChanged(SkScalar saturation, SkScalar value); |
235 | 235 |
236 private: | 236 private: |
237 // LocatedEventHandlerView overrides: | 237 // LocatedEventHandlerView overrides: |
238 virtual void ProcessEventAtLocation(const gfx::Point& point) OVERRIDE; | 238 virtual void ProcessEventAtLocation(const gfx::Point& point) OVERRIDE; |
239 | 239 |
240 // View overrides: | 240 // View overrides: |
241 virtual gfx::Size GetPreferredSize() OVERRIDE; | 241 virtual gfx::Size GetPreferredSize() const OVERRIDE; |
242 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; | 242 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; |
243 | 243 |
244 ColorChooserView* chooser_view_; | 244 ColorChooserView* chooser_view_; |
245 SkScalar hue_; | 245 SkScalar hue_; |
246 gfx::Point marker_position_; | 246 gfx::Point marker_position_; |
247 | 247 |
248 DISALLOW_COPY_AND_ASSIGN(SaturationValueView); | 248 DISALLOW_COPY_AND_ASSIGN(SaturationValueView); |
249 }; | 249 }; |
250 | 250 |
251 ColorChooserView::SaturationValueView::SaturationValueView( | 251 ColorChooserView::SaturationValueView::SaturationValueView( |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 SkScalar saturation = SkScalarDiv( | 285 SkScalar saturation = SkScalarDiv( |
286 SkIntToScalar(point.x() - kBorderWidth), scalar_size); | 286 SkIntToScalar(point.x() - kBorderWidth), scalar_size); |
287 SkScalar value = SK_Scalar1 - SkScalarDiv( | 287 SkScalar value = SK_Scalar1 - SkScalarDiv( |
288 SkIntToScalar(point.y() - kBorderWidth), scalar_size); | 288 SkIntToScalar(point.y() - kBorderWidth), scalar_size); |
289 saturation = SkScalarPin(saturation, 0, SK_Scalar1); | 289 saturation = SkScalarPin(saturation, 0, SK_Scalar1); |
290 value = SkScalarPin(value, 0, SK_Scalar1); | 290 value = SkScalarPin(value, 0, SK_Scalar1); |
291 OnSaturationValueChanged(saturation, value); | 291 OnSaturationValueChanged(saturation, value); |
292 chooser_view_->OnSaturationValueChosen(saturation, value); | 292 chooser_view_->OnSaturationValueChosen(saturation, value); |
293 } | 293 } |
294 | 294 |
295 gfx::Size ColorChooserView::SaturationValueView::GetPreferredSize() { | 295 gfx::Size ColorChooserView::SaturationValueView::GetPreferredSize() const { |
296 return gfx::Size(kSaturationValueSize + kBorderWidth * 2, | 296 return gfx::Size(kSaturationValueSize + kBorderWidth * 2, |
297 kSaturationValueSize + kBorderWidth * 2); | 297 kSaturationValueSize + kBorderWidth * 2); |
298 } | 298 } |
299 | 299 |
300 void ColorChooserView::SaturationValueView::OnPaint(gfx::Canvas* canvas) { | 300 void ColorChooserView::SaturationValueView::OnPaint(gfx::Canvas* canvas) { |
301 gfx::Rect color_bounds = bounds(); | 301 gfx::Rect color_bounds = bounds(); |
302 color_bounds.Inset(GetInsets()); | 302 color_bounds.Inset(GetInsets()); |
303 | 303 |
304 // Paints horizontal gradient first for saturation. | 304 // Paints horizontal gradient first for saturation. |
305 SkScalar hsv[3] = { hue_, SK_Scalar1, SK_Scalar1 }; | 305 SkScalar hsv[3] = { hue_, SK_Scalar1, SK_Scalar1 }; |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
472 const ui::KeyEvent& key_event) { | 472 const ui::KeyEvent& key_event) { |
473 if (key_event.key_code() != ui::VKEY_RETURN && | 473 if (key_event.key_code() != ui::VKEY_RETURN && |
474 key_event.key_code() != ui::VKEY_ESCAPE) | 474 key_event.key_code() != ui::VKEY_ESCAPE) |
475 return false; | 475 return false; |
476 | 476 |
477 GetWidget()->Close(); | 477 GetWidget()->Close(); |
478 return true; | 478 return true; |
479 } | 479 } |
480 | 480 |
481 } // namespace views | 481 } // namespace views |
OLD | NEW |