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
3 // found in the LICENSE file.
5 #ifndef UI_VIEWS_COLOR_CHOOSER_COLOR_CHOOSER_VIEW_H_
6 #define UI_VIEWS_COLOR_CHOOSER_COLOR_CHOOSER_VIEW_H_
8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h"
10 #include "third_party/skia/include/core/SkColor.h"
11 #include "third_party/skia/include/core/SkScalar.h"
12 #include "ui/views/controls/textfield/textfield_controller.h"
13 #include "ui/views/views_export.h"
14 #include "ui/views/widget/widget_delegate.h"
18 class ColorChooserListener;
21 // ColorChooserView provides the UI to choose a color by mouse and/or keyboard.
22 // It is typically used for <input type="color">. Currently the user can
23 // choose a color by dragging over the bar for hue and the area for saturation
25 class VIEWS_EXPORT ColorChooserView : public WidgetDelegateView,
26 public TextfieldController {
28 ColorChooserView(ColorChooserListener* listener, SkColor initial_color);
29 ~ColorChooserView() override;
31 // Called when its color value is changed in the web contents.
32 void OnColorChanged(SkColor color);
34 // Called when the user chooses a hue from the UI.
35 void OnHueChosen(SkScalar hue);
37 // Called when the user chooses saturation/value from the UI.
38 void OnSaturationValueChosen(SkScalar saturation, SkScalar value);
40 float hue() const { return hsv_[0]; }
41 float saturation() const { return hsv_[1]; }
42 float value() const { return hsv_[2]; }
43 void set_listener(ColorChooserListener* listener) { listener_ = listener; }
47 class SaturationValueView;
48 class SelectedColorPatchView;
50 // WidgetDelegate overrides:
51 bool CanMinimize() const override;
52 View* GetInitiallyFocusedView() override;
53 ui::ModalType GetModalType() const override;
54 void WindowClosing() override;
55 View* GetContentsView() override;
57 // TextfieldController overrides:
58 void ContentsChanged(Textfield* sender,
59 const base::string16& new_contents) override;
60 bool HandleKeyEvent(Textfield* sender,
61 const ui::KeyEvent& key_event) override;
63 // The current color in HSV coordinate.
66 // The pointer to the current color chooser for callbacks. It doesn't take
67 // ownership on |listener_| so the user of this class should take care of
68 // its lifetime. See chrome/browser/ui/browser.cc for example.
69 ColorChooserListener* listener_;
71 // Child views. These are owned as part of the normal views hierarchy.
72 // The view of hue chooser.
75 // The view of saturation/value choosing area.
76 SaturationValueView* saturation_value_;
78 // The textfield to write the color explicitly.
79 Textfield* textfield_;
81 // The rectangle to denote the selected color.
82 SelectedColorPatchView* selected_color_patch_;
84 DISALLOW_COPY_AND_ASSIGN(ColorChooserView);
89 #endif // UI_VIEWS_COLOR_CHOOSER_COLOR_CHOOSER_VIEW_H_