Chromium Code Reviews| Index: ui/views/color_chooser/color_chooser_view.h |
| diff --git a/ui/views/color_chooser/color_chooser_view.h b/ui/views/color_chooser/color_chooser_view.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..22ead5c88903006ded5078b84e1b887fd0f740d0 |
| --- /dev/null |
| +++ b/ui/views/color_chooser/color_chooser_view.h |
| @@ -0,0 +1,87 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef UI_VIEWS_COLOR_CHOOSER_COLOR_CHOOSER_VIEW_H_ |
| +#define UI_VIEWS_COLOR_CHOOSER_COLOR_CHOOSER_VIEW_H_ |
| +#pragma once |
| + |
| +#include "base/basictypes.h" |
| +#include "base/compiler_specific.h" |
| +#include "third_party/skia/include/core/SkColor.h" |
| +#include "third_party/skia/include/core/SkScalar.h" |
| +#include "ui/views/controls/textfield/textfield_controller.h" |
| +#include "ui/views/views_export.h" |
| +#include "ui/views/widget/widget_delegate.h" |
| + |
| +namespace views { |
| + |
| +class ColorChooserListener; |
| +class KeyEvent; |
| +class Textfield; |
| + |
| +// ColorChooserView provides the UI to choose a color by mouse and/or keyboard. |
| +// It is typically used for <input type="color">. Currently the user can |
| +// choose a color by dragging over the bar for hue and the area for saturation |
| +// and value. |
| +class VIEWS_EXPORT ColorChooserView : public WidgetDelegateView, |
| + public TextfieldController { |
| + public: |
| + ColorChooserView(ColorChooserListener* listener, SkColor initial_color); |
| + virtual ~ColorChooserView(); |
| + |
| + // Called when its owning window will be closed. |
| + void OnOwningWindowClosed(); |
| + |
| + // Called when its color value is changed in the web contents. |
| + void OnColorChanged(SkColor color); |
| + |
| + // Called when the user chooses a hue from the UI. |
| + void OnHueChosen(SkScalar hue); |
| + |
| + // Called when the user chooses saturation/value from the UI. |
| + void OnSaturationValueChosen(SkScalar saturation, SkScalar value); |
| + |
| + float hue() const { return hsv_[0]; } |
| + float saturation() const { return hsv_[1]; } |
| + float value() const { return hsv_[2]; } |
| + |
| + private: |
| + class HueView; |
| + class SaturationValueView; |
| + |
| + // WidgetDelegate overrides: |
| + virtual ui::ModalType GetModalType() const OVERRIDE; |
| + virtual void WindowClosing() OVERRIDE; |
| + virtual View* GetContentsView() OVERRIDE; |
| + |
| + // TextfieldController overrides: |
| + virtual void ContentsChanged(Textfield* sender, |
| + const string16& new_contents) OVERRIDE; |
| + virtual bool HandleKeyEvent(Textfield* sender, |
| + const KeyEvent& key_event) OVERRIDE; |
| + |
| + // The current color in HSV coordinate. |
| + SkScalar hsv_[3]; |
| + |
| + // The pointer to the current color chooser for callbacks. No ownership. |
|
Peter Kasting
2012/06/21 18:46:16
Nit: Does "No ownership" mean "This outlives us"?
Jun Mukai
2012/06/22 09:39:35
Here I expected another class should take care of
|
| + ColorChooserListener* listener_; |
| + |
| + // The view of hue chooser. No ownership because its ownership is taken in |
|
Peter Kasting
2012/06/21 18:46:16
Nit: How about just putting this comment above the
Jun Mukai
2012/06/22 09:39:35
Done.
|
| + // another way. |
| + HueView* hue_; |
| + |
| + // The view of saturation/value choosing area. No ownership because its |
| + // ownership is taken in another way. |
| + SaturationValueView* saturation_value_; |
| + |
| + // The textfield to write the color explicitly. No ownership because its |
| + // ownership is taken in another way. |
| + Textfield* textfield_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(ColorChooserView); |
| +}; |
| + |
| +} // namespace views |
| + |
| +#endif // UI_VIEWS_COLOR_CHOOSER_COLOR_CHOOSER_VIEW_H_ |