OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <windows.h> | 5 #include <windows.h> |
6 | 6 |
7 #include "chrome/browser/platform_util.h" | 7 #include "chrome/browser/platform_util.h" |
8 #include "chrome/browser/ui/browser_dialogs.h" | 8 #include "chrome/browser/ui/browser_dialogs.h" |
9 #include "chrome/browser/ui/views/color_chooser_dialog.h" | 9 #include "chrome/browser/ui/views/color_chooser_dialog.h" |
10 #include "content/public/browser/color_chooser.h" | 10 #include "content/public/browser/color_chooser.h" |
11 #include "content/public/browser/render_view_host.h" | 11 #include "content/public/browser/render_view_host.h" |
12 #include "content/public/browser/render_widget_host_view.h" | 12 #include "content/public/browser/render_widget_host_view.h" |
13 #include "content/public/browser/web_contents.h" | 13 #include "content/public/browser/web_contents.h" |
14 #include "ui/views/color_chooser/color_chooser_listener.h" | 14 #include "ui/views/color_chooser/color_chooser_listener.h" |
15 | 15 |
16 class ColorChooserWin : public content::ColorChooser, | 16 class ColorChooserWin : public content::ColorChooser, |
17 public views::ColorChooserListener { | 17 public views::ColorChooserListener { |
18 public: | 18 public: |
19 static ColorChooserWin* Open(content::WebContents* web_contents, | 19 static ColorChooserWin* Open(content::WebContents* web_contents, |
20 SkColor initial_color); | 20 SkColor initial_color); |
21 | 21 |
22 ColorChooserWin(content::WebContents* web_contents, | 22 ColorChooserWin(content::WebContents* web_contents, |
23 SkColor initial_color); | 23 SkColor initial_color); |
24 ~ColorChooserWin(); | 24 ~ColorChooserWin(); |
25 | 25 |
26 // content::ColorChooser overrides: | 26 // content::ColorChooser overrides: |
27 virtual void End() OVERRIDE {} | 27 virtual void End() OVERRIDE; |
28 virtual void SetSelectedColor(SkColor color) OVERRIDE {} | 28 virtual void SetSelectedColor(SkColor color) OVERRIDE {} |
29 | 29 |
30 // views::ColorChooserListener overrides: | 30 // views::ColorChooserListener overrides: |
31 virtual void OnColorChosen(SkColor color); | 31 virtual void OnColorChosen(SkColor color); |
32 virtual void OnColorChooserDialogClosed(); | 32 virtual void OnColorChooserDialogClosed(); |
33 | 33 |
34 private: | 34 private: |
35 static ColorChooserWin* current_color_chooser_; | 35 static ColorChooserWin* current_color_chooser_; |
36 | 36 |
37 // The web contents invoking the color chooser. No ownership. because it will | 37 // The web contents invoking the color chooser. No ownership. because it will |
(...skipping 21 matching lines...) Expand all Loading... | |
59 color_chooser_dialog_ = new ColorChooserDialog(this, | 59 color_chooser_dialog_ = new ColorChooserDialog(this, |
60 initial_color, | 60 initial_color, |
61 owning_window); | 61 owning_window); |
62 } | 62 } |
63 | 63 |
64 ColorChooserWin::~ColorChooserWin() { | 64 ColorChooserWin::~ColorChooserWin() { |
65 // Always call End() before destroying. | 65 // Always call End() before destroying. |
66 DCHECK(!color_chooser_dialog_); | 66 DCHECK(!color_chooser_dialog_); |
67 } | 67 } |
68 | 68 |
69 void ColorChooserWin::End() { | |
70 // While we can't programmatically close the dialog, we should at least have | |
71 // the dialog finalize state and inform listeners that it's closed, so that | |
72 // ColorChooserDialog::DidCloseDialog won't call the listener after it has | |
73 // been destroyed. | |
74 // If we don't do this we the ColorChooserDialog::DidCloseDialog will try to | |
75 // call the listener after it has been destroyed. | |
Peter Kasting
2013/08/30 19:35:47
Grammar issue and redundancy. Here's a cleanup at
keishi
2013/08/30 19:42:43
This is better. Thanks. Done.
| |
76 OnColorChooserDialogClosed(); | |
77 } | |
78 | |
69 void ColorChooserWin::OnColorChosen(SkColor color) { | 79 void ColorChooserWin::OnColorChosen(SkColor color) { |
70 if (web_contents_) | 80 if (web_contents_) |
71 web_contents_->DidChooseColorInColorChooser(color); | 81 web_contents_->DidChooseColorInColorChooser(color); |
72 } | 82 } |
73 | 83 |
74 void ColorChooserWin::OnColorChooserDialogClosed() { | 84 void ColorChooserWin::OnColorChooserDialogClosed() { |
75 if (color_chooser_dialog_.get()) { | 85 if (color_chooser_dialog_.get()) { |
76 color_chooser_dialog_->ListenerDestroyed(); | 86 color_chooser_dialog_->ListenerDestroyed(); |
77 color_chooser_dialog_ = NULL; | 87 color_chooser_dialog_ = NULL; |
78 } | 88 } |
79 DCHECK(current_color_chooser_ == this); | 89 DCHECK(current_color_chooser_ == this); |
80 current_color_chooser_ = NULL; | 90 current_color_chooser_ = NULL; |
81 if (web_contents_) | 91 if (web_contents_) |
82 web_contents_->DidEndColorChooser(); | 92 web_contents_->DidEndColorChooser(); |
83 } | 93 } |
84 | 94 |
85 namespace chrome { | 95 namespace chrome { |
86 | 96 |
87 content::ColorChooser* ShowColorChooser(content::WebContents* web_contents, | 97 content::ColorChooser* ShowColorChooser(content::WebContents* web_contents, |
88 SkColor initial_color) { | 98 SkColor initial_color) { |
89 return ColorChooserWin::Open(web_contents, initial_color); | 99 return ColorChooserWin::Open(web_contents, initial_color); |
90 } | 100 } |
91 | 101 |
92 } // namespace chrome | 102 } // namespace chrome |
OLD | NEW |