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 "content/public/browser/color_chooser.h" | 5 #include "content/public/browser/color_chooser.h" |
6 #include "content/public/browser/web_contents.h" | |
7 #include "ui/views/color_chooser/color_chooser_listener.h" | |
8 #include "ui/views/color_chooser/color_chooser_view.h" | |
9 #include "ui/views/widget/widget.h" | |
6 | 10 |
7 #include "base/logging.h" | 11 |
12 namespace { | |
13 | |
14 class ColorChooserAura : public content::ColorChooser, | |
15 public views::ColorChooserListener { | |
16 public: | |
17 ColorChooserAura(int identifier, | |
18 content::WebContents* tab, | |
19 SkColor initial_color); | |
20 | |
21 private: | |
22 // content::ColorChooser overrides: | |
23 virtual void End() OVERRIDE; | |
24 virtual void SetSelectedColor(SkColor color) OVERRIDE; | |
25 | |
26 // views::ColorChooserListener overrides: | |
27 virtual void OnColorChosen(SkColor color) OVERRIDE; | |
28 virtual void OnColorChooserDialogClosed() OVERRIDE; | |
29 | |
30 content::WebContents* tab_; | |
Peter Kasting
2012/06/19 21:10:31
Nit: Add comments about these, especially the owne
Jun Mukai
2012/06/20 09:29:08
Done.
| |
31 views::ColorChooserView* view_; | |
32 | |
33 DISALLOW_COPY_AND_ASSIGN(ColorChooserAura); | |
34 }; | |
35 | |
36 ColorChooserAura::ColorChooserAura(int identifier, | |
37 content::WebContents* tab, | |
38 SkColor initial_color) | |
39 : ColorChooser(identifier), | |
40 tab_(tab) { | |
41 view_ = new views::ColorChooserView(this, initial_color); | |
42 views::Widget* widget = views::Widget::CreateWindow(view_); | |
43 widget->SetAlwaysOnTop(true); | |
44 widget->Show(); | |
45 } | |
46 | |
47 void ColorChooserAura::OnColorChosen(SkColor color) { | |
48 if (tab_) | |
49 tab_->DidChooseColorInColorChooser(identifier(), color); | |
50 } | |
51 | |
52 void ColorChooserAura::OnColorChooserDialogClosed() { | |
53 if (tab_) | |
54 tab_->DidEndColorChooser(identifier()); | |
55 view_ = NULL; | |
56 } | |
57 | |
58 void ColorChooserAura::End() { | |
59 if (view_) { | |
60 view_->OnOwningWindowClosed(); | |
61 view_ = NULL; | |
62 } | |
63 } | |
64 | |
65 void ColorChooserAura::SetSelectedColor(SkColor color) { | |
66 if (view_) | |
67 view_->OnColorChanged(color); | |
68 } | |
69 | |
70 } // namespace | |
8 | 71 |
9 // static | 72 // static |
10 content::ColorChooser* content::ColorChooser::Create( | 73 content::ColorChooser* content::ColorChooser::Create( |
11 int identifier, content::WebContents* tab, SkColor initial_color) { | 74 int identifier, content::WebContents* tab, SkColor initial_color) { |
12 NOTIMPLEMENTED(); | 75 return new ColorChooserAura(identifier, tab, initial_color); |
13 return NULL; | |
14 } | 76 } |
OLD | NEW |