Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(860)

Side by Side Diff: chrome/browser/ui/views/color_chooser_win.cc

Issue 23785003: ColorChooserWin::End should act like the dialog has closed (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Changed comment again. Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/views/color_chooser_dialog.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 // The ColorChooserDialog's listener is going away. Ideally we'd
71 // programmatically close the dialog at this point. Since that's impossible,
72 // we instead tell the dialog its listener is going away, so that the dialog
73 // doesn't try to communicate with a destroyed listener later. (We also tell
74 // the renderer the dialog is closed, since from the renderer's perspective
75 // it effectively is.)
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
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/color_chooser_dialog.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698