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. 4 5#ifndef UI_VIEWS_COLOR_CHOOSER_COLOR_CHOOSER_VIEW_H_ 6#define UI_VIEWS_COLOR_CHOOSER_COLOR_CHOOSER_VIEW_H_ 7 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" 15 16namespace views { 17 18class ColorChooserListener; 19class Textfield; 20 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 24// and value. 25class VIEWS_EXPORT ColorChooserView : public WidgetDelegateView, 26 public TextfieldController { 27 public: 28 ColorChooserView(ColorChooserListener* listener, SkColor initial_color); 29 virtual ~ColorChooserView(); 30 31 // Called when its color value is changed in the web contents. 32 void OnColorChanged(SkColor color); 33 34 // Called when the user chooses a hue from the UI. 35 void OnHueChosen(SkScalar hue); 36 37 // Called when the user chooses saturation/value from the UI. 38 void OnSaturationValueChosen(SkScalar saturation, SkScalar value); 39 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; } 44 45 private: 46 class HueView; 47 class SaturationValueView; 48 class SelectedColorPatchView; 49 50 // WidgetDelegate overrides: 51 virtual bool CanMinimize() const OVERRIDE; 52 virtual View* GetInitiallyFocusedView() OVERRIDE; 53 virtual ui::ModalType GetModalType() const OVERRIDE; 54 virtual void WindowClosing() OVERRIDE; 55 virtual View* GetContentsView() OVERRIDE; 56 57 // TextfieldController overrides: 58 virtual void ContentsChanged(Textfield* sender, 59 const base::string16& new_contents) OVERRIDE; 60 virtual bool HandleKeyEvent(Textfield* sender, 61 const ui::KeyEvent& key_event) OVERRIDE; 62 63 // The current color in HSV coordinate. 64 SkScalar hsv_[3]; 65 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_; 70 71 // Child views. These are owned as part of the normal views hierarchy. 72 // The view of hue chooser. 73 HueView* hue_; 74 75 // The view of saturation/value choosing area. 76 SaturationValueView* saturation_value_; 77 78 // The textfield to write the color explicitly. 79 Textfield* textfield_; 80 81 // The rectangle to denote the selected color. 82 SelectedColorPatchView* selected_color_patch_; 83 84 DISALLOW_COPY_AND_ASSIGN(ColorChooserView); 85}; 86 87} // namespace views 88 89#endif // UI_VIEWS_COLOR_CHOOSER_COLOR_CHOOSER_VIEW_H_ 90