Commit 998d3505 authored by mukai@chromium.org's avatar mukai@chromium.org

Fix color chooser cleanup process.

- In case of crbug.com/139441, End() should close the window but it also schedules OnColorChooserDialogClosed() and this has been released already.  That call isn't necessary in this case, so set_listener to NULL.
- tab is expected to call DidEndColorChooser() everytime it ends, thus it should be called in End() too. the callback to prevent the calling


BUG=139441


Review URL: https://chromiumcodereview.appspot.com/10821087

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@149380 0039d316-1c4b-4281-b951-d872f2087c98
parent df5883f0
...@@ -47,6 +47,7 @@ ColorChooserAura::ColorChooserAura(int identifier, ...@@ -47,6 +47,7 @@ ColorChooserAura::ColorChooserAura(int identifier,
SkColor initial_color) SkColor initial_color)
: ColorChooser(identifier), : ColorChooser(identifier),
tab_(tab) { tab_(tab) {
DCHECK(tab_);
view_ = new views::ColorChooserView(this, initial_color); view_ = new views::ColorChooserView(this, initial_color);
widget_ = views::Widget::CreateWindow(view_); widget_ = views::Widget::CreateWindow(view_);
widget_->SetAlwaysOnTop(true); widget_->SetAlwaysOnTop(true);
...@@ -54,23 +55,24 @@ ColorChooserAura::ColorChooserAura(int identifier, ...@@ -54,23 +55,24 @@ ColorChooserAura::ColorChooserAura(int identifier,
} }
void ColorChooserAura::OnColorChosen(SkColor color) { void ColorChooserAura::OnColorChosen(SkColor color) {
if (tab_) tab_->DidChooseColorInColorChooser(identifier(), color);
tab_->DidChooseColorInColorChooser(identifier(), color);
} }
void ColorChooserAura::OnColorChooserDialogClosed() { void ColorChooserAura::OnColorChooserDialogClosed() {
if (tab_)
tab_->DidEndColorChooser(identifier());
view_ = NULL; view_ = NULL;
widget_ = NULL; widget_ = NULL;
tab_->DidEndColorChooser(identifier());
} }
void ColorChooserAura::End() { void ColorChooserAura::End() {
if (widget_ && widget_->IsVisible()) { if (widget_ && widget_->IsVisible()) {
view_->set_listener(NULL);
widget_->Close(); widget_->Close();
tab_ = NULL;
view_ = NULL; view_ = NULL;
widget_ = NULL; widget_ = NULL;
// DidEndColorChooser will invoke Browser::DidEndColorChooser, which deletes
// this. Take care of the call order.
tab_->DidEndColorChooser(identifier());
} }
} }
......
...@@ -339,7 +339,8 @@ void ColorChooserView::OnColorChanged(SkColor color) { ...@@ -339,7 +339,8 @@ void ColorChooserView::OnColorChanged(SkColor color) {
void ColorChooserView::OnHueChosen(SkScalar hue) { void ColorChooserView::OnHueChosen(SkScalar hue) {
hsv_[0] = hue; hsv_[0] = hue;
SkColor color = SkHSVToColor(255, hsv_); SkColor color = SkHSVToColor(255, hsv_);
listener_->OnColorChosen(color); if (listener_)
listener_->OnColorChosen(color);
saturation_value_->OnHueChanged(hue); saturation_value_->OnHueChanged(hue);
textfield_->SetText(GetColorText(color)); textfield_->SetText(GetColorText(color));
} }
...@@ -349,7 +350,8 @@ void ColorChooserView::OnSaturationValueChosen(SkScalar saturation, ...@@ -349,7 +350,8 @@ void ColorChooserView::OnSaturationValueChosen(SkScalar saturation,
hsv_[1] = saturation; hsv_[1] = saturation;
hsv_[2] = value; hsv_[2] = value;
SkColor color = SkHSVToColor(255, hsv_); SkColor color = SkHSVToColor(255, hsv_);
listener_->OnColorChosen(color); if (listener_)
listener_->OnColorChosen(color);
textfield_->SetText(GetColorText(color)); textfield_->SetText(GetColorText(color));
} }
...@@ -375,7 +377,8 @@ void ColorChooserView::ContentsChanged(Textfield* sender, ...@@ -375,7 +377,8 @@ void ColorChooserView::ContentsChanged(Textfield* sender,
SkColor color = SK_ColorBLACK; SkColor color = SK_ColorBLACK;
if (GetColorFromText(new_contents, &color)) { if (GetColorFromText(new_contents, &color)) {
SkColorToHSV(color, hsv_); SkColorToHSV(color, hsv_);
listener_->OnColorChosen(color); if (listener_)
listener_->OnColorChosen(color);
hue_->OnHueChanged(hsv_[0]); hue_->OnHueChanged(hsv_[0]);
saturation_value_->OnHueChanged(hsv_[0]); saturation_value_->OnHueChanged(hsv_[0]);
saturation_value_->OnSaturationValueChanged(hsv_[1], hsv_[2]); saturation_value_->OnSaturationValueChanged(hsv_[1], hsv_[2]);
......
...@@ -41,6 +41,7 @@ class VIEWS_EXPORT ColorChooserView : public WidgetDelegateView, ...@@ -41,6 +41,7 @@ class VIEWS_EXPORT ColorChooserView : public WidgetDelegateView,
float hue() const { return hsv_[0]; } float hue() const { return hsv_[0]; }
float saturation() const { return hsv_[1]; } float saturation() const { return hsv_[1]; }
float value() const { return hsv_[2]; } float value() const { return hsv_[2]; }
void set_listener(ColorChooserListener* listener) { listener_ = listener; }
private: private:
class HueView; class HueView;
......
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