Commit 63212d34 authored by Elly Fong-Jones's avatar Elly Fong-Jones Committed by Chromium LUCI CQ

views: make ColorChooserView neither a WidgetDelegate nor a View.

This CL enacts the "class splitting refactor"
(//docs/ui/views/class_splitting.md) on ColorChooserView, breaking it
into:

* A controller class called ColorChooser, whose lifetime is fully
  controlled by the client, and which is safe to call at any point in
  the lifecycle of the matching Widget/Views/etc
* Two helper objects (instances of WidgetDelegate and View respectively)
  whose lifetimes are fully controlled by Views

This CL serves as a prototype for how the class splitting refactor looks
when applied to production code.

Instead, have it use only the public API on WidgetDelegate.

Bug: 1075649
Change-Id: I84655a9c204a9f5f88767ac792ce1abc846feda0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2622995
Commit-Queue: Elly Fong-Jones <ellyjones@chromium.org>
Reviewed-by: default avatarAllen Bauer <kylixrd@chromium.org>
Cr-Commit-Position: refs/heads/master@{#846358}
parent 9e150f6e
......@@ -9,33 +9,30 @@
#include "content/public/browser/web_contents.h"
#include "ui/views/color_chooser/color_chooser_view.h"
#include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_delegate.h"
ColorChooserAura::ColorChooserAura(content::WebContents* web_contents,
SkColor initial_color)
: web_contents_(web_contents) {
view_ = new views::ColorChooserView(this, initial_color);
widget_ = views::Widget::CreateWindowWithParent(
view_, web_contents->GetTopLevelNativeWindow());
widget_->Show();
chooser_ = std::make_unique<views::ColorChooser>(this, initial_color);
chooser_widget_ = base::WrapUnique(views::Widget::CreateWindowWithParent(
chooser_->MakeWidgetDelegate(), web_contents->GetTopLevelNativeWindow()));
chooser_widget_->Show();
}
ColorChooserAura::~ColorChooserAura() = default;
void ColorChooserAura::OnColorChosen(SkColor color) {
if (web_contents_)
web_contents_->DidChooseColorInColorChooser(color);
}
void ColorChooserAura::OnColorChooserDialogClosed() {
view_ = nullptr;
widget_ = nullptr;
DidEndColorChooser();
}
void ColorChooserAura::End() {
if (widget_) {
view_->set_listener(nullptr);
widget_->Close();
view_ = nullptr;
widget_ = nullptr;
if (chooser_widget_) {
// DidEndColorChooser will invoke Browser::DidEndColorChooser, which deletes
// this. Take care of the call order.
DidEndColorChooser();
......@@ -48,8 +45,7 @@ void ColorChooserAura::DidEndColorChooser() {
}
void ColorChooserAura::SetSelectedColor(SkColor color) {
if (view_)
view_->OnColorChanged(color);
chooser_->OnColorChanged(color);
}
// static
......
......@@ -9,14 +9,14 @@
#include "base/macros.h"
#include "content/public/browser/color_chooser.h"
#include "ui/views/color_chooser/color_chooser_listener.h"
#include "ui/views/widget/unique_widget_ptr.h"
namespace content {
class WebContents;
}
namespace views {
class ColorChooserView;
class Widget;
class ColorChooser;
}
// TODO(mukai): rename this as -Ash and move to c/b/ui/ash after Linux-aura
......@@ -29,6 +29,7 @@ class ColorChooserAura : public content::ColorChooser,
private:
ColorChooserAura(content::WebContents* web_contents, SkColor initial_color);
~ColorChooserAura() override;
// content::ColorChooser overrides:
void End() override;
......@@ -40,13 +41,8 @@ class ColorChooserAura : public content::ColorChooser,
void DidEndColorChooser();
// The actual view of the color chooser. No ownership because its parent
// view will take care of its lifetime.
views::ColorChooserView* view_;
// The widget for the color chooser. No ownership because it's released
// automatically when closed.
views::Widget* widget_;
std::unique_ptr<views::ColorChooser> chooser_;
views::UniqueWidgetPtr chooser_widget_;
// The web contents invoking the color chooser. No ownership because it will
// outlive this class.
......
......@@ -22,6 +22,7 @@
#include "ui/views/color_chooser/color_chooser_view.h"
#include "ui/views/controls/textfield/textfield.h"
#include "ui/views/test/views_test_base.h"
#include "ui/views/widget/widget_delegate.h"
#include "ui/views/widget/widget_utils.h"
namespace {
......@@ -42,11 +43,18 @@ class ColorChooserTest : public views::ViewsTestBase {
void SetUp() override {
ViewsTestBase::SetUp();
chooser_ =
std::make_unique<views::ColorChooserView>(&listener_, SK_ColorGREEN);
chooser_->SetBounds(0, 0, 400, 300);
chooser_ = std::make_unique<views::ColorChooser>(&listener_, SK_ColorGREEN);
// Icky: we can't use our own WidgetDelegate for CreateTestWidget, but we
// want to follow the production code path here regardless, so we create our
// own delegate, pull the contents view out of it, and stick it into the
// test widget. In production Views would handle that step itself.
auto delegate = chooser_->MakeWidgetDelegate();
auto* view = delegate->TransferOwnershipOfContentsView();
view->SetBounds(0, 0, 400, 300);
widget_ = CreateTestWidget(views::Widget::InitParams::TYPE_WINDOW);
widget_->GetContentsView()->AddChildView(chooser());
widget_->GetContentsView()->AddChildView(std::move(view));
generator_ = std::make_unique<ui::test::EventGenerator>(
views::GetRootWindow(widget_.get()), widget_->GetNativeWindow());
generator_->set_assume_window_at_origin(false);
......@@ -58,7 +66,7 @@ class ColorChooserTest : public views::ViewsTestBase {
ViewsTestBase::TearDown();
}
views::ColorChooserView* chooser() { return chooser_.get(); }
views::ColorChooser* chooser() { return chooser_.get(); }
ui::test::EventGenerator* generator() { return generator_.get(); }
void ExpectExactHSV(float h, float s, float v) const {
......@@ -115,7 +123,7 @@ class ColorChooserTest : public views::ViewsTestBase {
private:
TestChooserListener listener_;
std::unique_ptr<views::ColorChooserView> chooser_;
std::unique_ptr<views::ColorChooser> chooser_;
std::unique_ptr<views::Widget> widget_;
std::unique_ptr<ui::test::EventGenerator> generator_;
};
......
......@@ -35,6 +35,7 @@
#include "ui/views/layout/box_layout.h"
#include "ui/views/layout/grid_layout.h"
#include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_delegate.h"
namespace {
......@@ -124,13 +125,14 @@ void DrawGradientRect(const gfx::Rect& rect,
namespace views {
////////////////////////////////////////////////////////////////////////////////
// ColorChooserView::HueView
// HueView
//
// The class to choose the hue of the color. It draws a vertical bar and
// the indicator for the currently selected hue.
class ColorChooserView::HueView : public LocatedEventHandlerView {
class HueView : public LocatedEventHandlerView {
public:
explicit HueView(ColorChooserView* chooser_view);
using HueChangedCallback = base::RepeatingCallback<void(SkScalar)>;
explicit HueView(const HueChangedCallback& changed_callback);
void OnHueChanged(SkScalar hue);
......@@ -142,16 +144,16 @@ class ColorChooserView::HueView : public LocatedEventHandlerView {
gfx::Size CalculatePreferredSize() const override;
void OnPaint(gfx::Canvas* canvas) override;
ColorChooserView* chooser_view_;
HueChangedCallback changed_callback_;
int level_;
DISALLOW_COPY_AND_ASSIGN(HueView);
};
ColorChooserView::HueView::HueView(ColorChooserView* chooser_view)
: chooser_view_(chooser_view), level_(0) {}
HueView::HueView(const HueChangedCallback& changed_callback)
: changed_callback_(changed_callback), level_(0) {}
void ColorChooserView::HueView::OnHueChanged(SkScalar hue) {
void HueView::OnHueChanged(SkScalar hue) {
SkScalar height = SkIntToScalar(kSaturationValueSize - 1);
SkScalar hue_max = SkIntToScalar(360);
int level = (hue_max - hue) * height / hue_max;
......@@ -162,23 +164,22 @@ void ColorChooserView::HueView::OnHueChanged(SkScalar hue) {
}
}
void ColorChooserView::HueView::ProcessEventAtLocation(
const gfx::Point& point) {
void HueView::ProcessEventAtLocation(const gfx::Point& point) {
level_ =
std::max(kBorderWidth, std::min(height() - 1 - kBorderWidth, point.y()));
int base_height = kSaturationValueSize - 1;
chooser_view_->OnHueChosen(360.f * (base_height - (level_ - kBorderWidth)) /
changed_callback_.Run(360.f * (base_height - (level_ - kBorderWidth)) /
base_height);
SchedulePaint();
}
gfx::Size ColorChooserView::HueView::CalculatePreferredSize() const {
gfx::Size HueView::CalculatePreferredSize() const {
// We put indicators on the both sides of the hue bar.
return gfx::Size(kHueBarWidth + kHueIndicatorSize * 2 + kBorderWidth * 2,
kSaturationValueSize + kBorderWidth * 2);
}
void ColorChooserView::HueView::OnPaint(gfx::Canvas* canvas) {
void HueView::OnPaint(gfx::Canvas* canvas) {
SkScalar hsv[3];
// In the hue bar, saturation and value for the color should be always 100%.
hsv[1] = SK_Scalar1;
......@@ -223,14 +224,17 @@ void ColorChooserView::HueView::OnPaint(gfx::Canvas* canvas) {
}
////////////////////////////////////////////////////////////////////////////////
// ColorChooserView::SaturationValueView
// SaturationValueView
//
// The class to choose the saturation and the value of the color. It draws
// a square area and the indicator for the currently selected saturation and
// value.
class ColorChooserView::SaturationValueView : public LocatedEventHandlerView {
class SaturationValueView : public LocatedEventHandlerView {
public:
explicit SaturationValueView(ColorChooserView* chooser_view);
using SaturationValueChangedCallback =
base::RepeatingCallback<void(SkScalar, SkScalar)>;
explicit SaturationValueView(
const SaturationValueChangedCallback& changed_callback);
void OnHueChanged(SkScalar hue);
void OnSaturationValueChanged(SkScalar saturation, SkScalar value);
......@@ -243,28 +247,27 @@ class ColorChooserView::SaturationValueView : public LocatedEventHandlerView {
gfx::Size CalculatePreferredSize() const override;
void OnPaint(gfx::Canvas* canvas) override;
ColorChooserView* chooser_view_;
SaturationValueChangedCallback changed_callback_;
SkScalar hue_;
gfx::Point marker_position_;
DISALLOW_COPY_AND_ASSIGN(SaturationValueView);
};
ColorChooserView::SaturationValueView::SaturationValueView(
ColorChooserView* chooser_view)
: chooser_view_(chooser_view), hue_(0) {
SaturationValueView::SaturationValueView(
const SaturationValueChangedCallback& changed_callback)
: changed_callback_(changed_callback), hue_(0) {
SetBorder(CreateSolidBorder(kBorderWidth, SK_ColorGRAY));
}
void ColorChooserView::SaturationValueView::OnHueChanged(SkScalar hue) {
void SaturationValueView::OnHueChanged(SkScalar hue) {
if (hue_ != hue) {
hue_ = hue;
SchedulePaint();
}
}
void ColorChooserView::SaturationValueView::OnSaturationValueChanged(
SkScalar saturation,
void SaturationValueView::OnSaturationValueChanged(SkScalar saturation,
SkScalar value) {
SkScalar scalar_size = SkIntToScalar(kSaturationValueSize - 1);
int x = SkScalarFloorToInt(saturation * scalar_size) + kBorderWidth;
......@@ -277,24 +280,22 @@ void ColorChooserView::SaturationValueView::OnSaturationValueChanged(
SchedulePaint();
}
void ColorChooserView::SaturationValueView::ProcessEventAtLocation(
const gfx::Point& point) {
void SaturationValueView::ProcessEventAtLocation(const gfx::Point& point) {
SkScalar scalar_size = SkIntToScalar(kSaturationValueSize - 1);
SkScalar saturation = (point.x() - kBorderWidth) / scalar_size;
SkScalar value = SK_Scalar1 - (point.y() - kBorderWidth) / scalar_size;
saturation = base::ClampToRange(saturation, 0.0f, SK_Scalar1);
value = base::ClampToRange(value, 0.0f, SK_Scalar1);
OnSaturationValueChanged(saturation, value);
chooser_view_->OnSaturationValueChosen(saturation, value);
changed_callback_.Run(saturation, value);
}
gfx::Size ColorChooserView::SaturationValueView::CalculatePreferredSize()
const {
gfx::Size SaturationValueView::CalculatePreferredSize() const {
return gfx::Size(kSaturationValueSize + kBorderWidth * 2,
kSaturationValueSize + kBorderWidth * 2);
}
void ColorChooserView::SaturationValueView::OnPaint(gfx::Canvas* canvas) {
void SaturationValueView::OnPaint(gfx::Canvas* canvas) {
gfx::Rect color_bounds = bounds();
color_bounds.Inset(GetInsets());
......@@ -329,10 +330,10 @@ void ColorChooserView::SaturationValueView::OnPaint(gfx::Canvas* canvas) {
}
////////////////////////////////////////////////////////////////////////////////
// ColorChooserView::SelectedColorPatchView
// SelectedColorPatchView
//
// A view to simply show the selected color in a rectangle.
class ColorChooserView::SelectedColorPatchView : public views::View {
class SelectedColorPatchView : public views::View {
public:
SelectedColorPatchView();
......@@ -342,12 +343,12 @@ class ColorChooserView::SelectedColorPatchView : public views::View {
DISALLOW_COPY_AND_ASSIGN(SelectedColorPatchView);
};
ColorChooserView::SelectedColorPatchView::SelectedColorPatchView() {
SelectedColorPatchView::SelectedColorPatchView() {
SetVisible(true);
SetBorder(CreateSolidBorder(kBorderWidth, SK_ColorGRAY));
}
void ColorChooserView::SelectedColorPatchView::SetColor(SkColor color) {
void SelectedColorPatchView::SetColor(SkColor color) {
if (!background())
SetBackground(CreateSolidBackground(color));
else
......@@ -355,29 +356,23 @@ void ColorChooserView::SelectedColorPatchView::SetColor(SkColor color) {
SchedulePaint();
}
////////////////////////////////////////////////////////////////////////////////
// ColorChooserView
//
ColorChooserView::ColorChooserView(ColorChooserListener* listener,
SkColor initial_color)
: listener_(listener) {
DCHECK(listener_);
SetModalType(ui::MODAL_TYPE_WINDOW);
SetBackground(CreateSolidBackground(SK_ColorLTGRAY));
SetLayoutManager(
std::unique_ptr<View> ColorChooser::BuildView() {
auto view = std::make_unique<View>();
tracker_.SetView(view.get());
view->SetBackground(CreateSolidBackground(SK_ColorLTGRAY));
view->SetLayoutManager(
std::make_unique<BoxLayout>(BoxLayout::Orientation::kVertical,
gfx::Insets(kMarginWidth), kMarginWidth));
auto container = std::make_unique<View>();
container->SetLayoutManager(std::make_unique<BoxLayout>(
BoxLayout::Orientation::kHorizontal, gfx::Insets(), kMarginWidth));
saturation_value_ =
container->AddChildView(std::make_unique<SaturationValueView>(this));
hue_ = container->AddChildView(std::make_unique<HueView>(this));
AddChildView(std::move(container));
saturation_value_ = container->AddChildView(
std::make_unique<SaturationValueView>(base::BindRepeating(
&ColorChooser::OnSaturationValueChosen, this->AsWeakPtr())));
hue_ = container->AddChildView(std::make_unique<HueView>(
base::BindRepeating(&ColorChooser::OnHueChosen, this->AsWeakPtr())));
view->AddChildView(std::move(container));
auto container2 = std::make_unique<View>();
GridLayout* layout =
......@@ -397,94 +392,127 @@ ColorChooserView::ColorChooserView(ColorChooserListener* listener,
textfield_ = layout->AddView(std::move(textfield));
selected_color_patch_ =
layout->AddView(std::make_unique<SelectedColorPatchView>());
AddChildView(std::move(container2));
view->AddChildView(std::move(container2));
OnColorChanged(initial_color_);
OnColorChanged(initial_color);
return view;
}
ColorChooserView::~ColorChooserView() = default;
bool ColorChooser::IsViewAttached() const {
return tracker_.view();
}
void ColorChooserView::OnColorChanged(SkColor color) {
SkColorToHSV(color, hsv_);
hue_->OnHueChanged(hsv_[0]);
saturation_value_->OnHueChanged(hsv_[0]);
saturation_value_->OnSaturationValueChanged(hsv_[1], hsv_[2]);
void ColorChooser::OnColorChanged(SkColor color) {
SetColor(color);
if (IsViewAttached()) {
hue_->OnHueChanged(hue());
saturation_value_->OnHueChanged(hue());
saturation_value_->OnSaturationValueChanged(saturation(), value());
selected_color_patch_->SetColor(color);
textfield_->SetText(GetColorText(color));
}
}
void ColorChooserView::OnHueChosen(SkScalar hue) {
hsv_[0] = hue;
SkColor color = SkHSVToColor(255, hsv_);
if (listener_)
listener_->OnColorChosen(color);
void ColorChooser::OnHueChosen(SkScalar hue) {
SetHue(hue);
SkColor color = GetColor();
saturation_value_->OnHueChanged(hue);
selected_color_patch_->SetColor(color);
textfield_->SetText(GetColorText(color));
}
void ColorChooserView::OnSaturationValueChosen(SkScalar saturation,
void ColorChooser::OnSaturationValueChosen(SkScalar saturation,
SkScalar value) {
hsv_[1] = saturation;
hsv_[2] = value;
SkColor color = SkHSVToColor(255, hsv_);
if (listener_)
listener_->OnColorChosen(color);
SetSaturationValue(saturation, value);
SkColor color = GetColor();
selected_color_patch_->SetColor(color);
textfield_->SetText(GetColorText(color));
}
View* ColorChooserView::hue_view_for_testing() {
View* ColorChooser::hue_view_for_testing() {
return hue_;
}
View* ColorChooserView::saturation_value_view_for_testing() {
View* ColorChooser::saturation_value_view_for_testing() {
return saturation_value_;
}
Textfield* ColorChooserView::textfield_for_testing() {
Textfield* ColorChooser::textfield_for_testing() {
return textfield_;
}
View* ColorChooserView::selected_color_patch_for_testing() {
View* ColorChooser::selected_color_patch_for_testing() {
return selected_color_patch_;
}
void ColorChooserView::ContentsChanged(Textfield* sender,
void ColorChooser::ContentsChanged(Textfield* sender,
const base::string16& new_contents) {
DCHECK(IsViewAttached());
SkColor color = SK_ColorBLACK;
if (GetColorFromText(new_contents, &color)) {
SkColorToHSV(color, hsv_);
if (listener_)
listener_->OnColorChosen(color);
hue_->OnHueChanged(hsv_[0]);
saturation_value_->OnHueChanged(hsv_[0]);
saturation_value_->OnSaturationValueChanged(hsv_[1], hsv_[2]);
SetColor(color);
hue_->OnHueChanged(hue());
saturation_value_->OnHueChanged(hue());
saturation_value_->OnSaturationValueChanged(saturation(), value());
selected_color_patch_->SetColor(color);
}
}
bool ColorChooserView::HandleKeyEvent(Textfield* sender,
bool ColorChooser::HandleKeyEvent(Textfield* sender,
const ui::KeyEvent& key_event) {
DCHECK(IsViewAttached());
if (key_event.type() != ui::ET_KEY_PRESSED ||
(key_event.key_code() != ui::VKEY_RETURN &&
key_event.key_code() != ui::VKEY_ESCAPE))
return false;
GetWidget()->Close();
tracker_.view()->GetWidget()->Close();
return true;
}
bool ColorChooserView::CanMinimize() const {
return false;
std::unique_ptr<WidgetDelegate> ColorChooser::MakeWidgetDelegate() {
DCHECK(!IsViewAttached());
auto delegate = std::make_unique<WidgetDelegate>();
delegate->SetCanMinimize(false);
delegate->SetContentsView(BuildView());
delegate->SetInitiallyFocusedView(textfield_);
delegate->SetModalType(ui::MODAL_TYPE_WINDOW);
delegate->RegisterWindowClosingCallback(
base::BindOnce(&ColorChooser::OnViewClosing, base::Unretained(this)));
return delegate;
}
View* ColorChooserView::GetInitiallyFocusedView() {
return textfield_;
ColorChooser::ColorChooser(ColorChooserListener* listener, SkColor initial)
: listener_(listener), initial_color_(initial) {}
ColorChooser::~ColorChooser() = default;
void ColorChooser::SetColor(SkColor color) {
SkColorToHSV(color, hsv_);
listener_->OnColorChosen(GetColor());
}
void ColorChooser::SetHue(SkScalar hue) {
hsv_[0] = hue;
listener_->OnColorChosen(GetColor());
}
void ColorChooser::SetSaturationValue(SkScalar saturation, SkScalar value) {
hsv_[1] = saturation;
hsv_[2] = value;
listener_->OnColorChosen(GetColor());
}
SkColor ColorChooser::GetColor() const {
return SkHSVToColor(255, hsv_);
}
void ColorChooserView::WindowClosing() {
if (listener_)
void ColorChooser::OnViewClosing() {
listener_->OnColorChooserDialogClosed();
}
......
......@@ -5,86 +5,102 @@
#ifndef UI_VIEWS_COLOR_CHOOSER_COLOR_CHOOSER_VIEW_H_
#define UI_VIEWS_COLOR_CHOOSER_COLOR_CHOOSER_VIEW_H_
#include <memory>
#include "base/compiler_specific.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.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/view.h"
#include "ui/views/view_tracker.h"
#include "ui/views/views_export.h"
#include "ui/views/widget/widget_delegate.h"
namespace views {
class ColorChooserListener;
class Textfield;
class WidgetDelegate;
class HueView;
class SaturationValueView;
class SelectedColorPatchView;
// ColorChooserView provides the UI to choose a color by mouse and/or keyboard.
// ColorChooser 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 {
//
// All public methods on ColorChooser are safe to call before, during, or after
// the existence of the corresponding Widget/Views/etc.
class VIEWS_EXPORT ColorChooser : public TextfieldController,
public base::SupportsWeakPtr<ColorChooser> {
public:
ColorChooserView(ColorChooserListener* listener, SkColor initial_color);
~ColorChooserView() override;
// Called when its color value is changed in the web contents.
void OnColorChanged(SkColor color);
ColorChooser(ColorChooserListener* listener, SkColor initial_color);
~ColorChooser() override;
// Called when the user chooses a hue from the UI.
void OnHueChosen(SkScalar hue);
// Construct the WidgetDelegate that should be used to show the actual dialog
// for this ColorChooser. It is only safe to call this once per ColorChooser
// instance.
std::unique_ptr<WidgetDelegate> MakeWidgetDelegate();
// Called when the user chooses saturation/value from the UI.
void OnSaturationValueChosen(SkScalar saturation, SkScalar value);
SkColor GetColor() const;
SkScalar hue() const { return hsv_[0]; }
SkScalar saturation() const { return hsv_[1]; }
SkScalar value() const { return hsv_[2]; }
float hue() const { return hsv_[0]; }
float saturation() const { return hsv_[1]; }
float value() const { return hsv_[2]; }
void set_listener(ColorChooserListener* listener) { listener_ = listener; }
bool IsViewAttached() const;
View* hue_view_for_testing();
View* saturation_value_view_for_testing();
Textfield* textfield_for_testing();
View* selected_color_patch_for_testing();
// Called when its color value is changed in the web contents.
void OnColorChanged(SkColor color);
// TextfieldController overrides:
// TextfieldController overrides, public for testing:
void ContentsChanged(Textfield* sender,
const base::string16& new_contents) override;
bool HandleKeyEvent(Textfield* sender,
const ui::KeyEvent& key_event) override;
View* hue_view_for_testing();
View* saturation_value_view_for_testing();
Textfield* textfield_for_testing();
View* selected_color_patch_for_testing();
private:
class HueView;
class SaturationValueView;
class SelectedColorPatchView;
std::unique_ptr<View> BuildView();
// WidgetDelegate overrides:
bool CanMinimize() const override;
View* GetInitiallyFocusedView() override;
void WindowClosing() override;
void SetColor(SkColor color);
void SetHue(SkScalar hue);
void SetSaturationValue(SkScalar saturation, SkScalar value);
void OnViewClosing();
// 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);
// The current color in HSV coordinate.
SkScalar hsv_[3];
// The pointer to the current color chooser for callbacks. It doesn't take
// ownership on |listener_| so the user of this class should take care of
// its lifetime. See chrome/browser/ui/browser.cc for example.
ColorChooserListener* listener_;
ViewTracker tracker_;
// Child views. These are owned as part of the normal views hierarchy.
// The view of hue chooser.
HueView* hue_;
HueView* hue_ = nullptr;
// The view of saturation/value choosing area.
SaturationValueView* saturation_value_;
// The textfield to write the color explicitly.
Textfield* textfield_;
SaturationValueView* saturation_value_ = nullptr;
// The rectangle to denote the selected color.
SelectedColorPatchView* selected_color_patch_;
SelectedColorPatchView* selected_color_patch_ = nullptr;
// The textfield to write the color explicitly.
Textfield* textfield_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(ColorChooserView);
SkColor initial_color_;
};
} // namespace views
......
......@@ -21,6 +21,7 @@ class VIEWS_EXPORT ViewTracker : public ViewObserver {
void SetView(View* view);
View* view() { return view_; }
const View* view() const { return view_; }
// ViewObserver:
void OnViewIsDeleting(View* observed_view) override;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment