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 // The web contents invoking the color chooser. No ownership because it will |
| 31 // outlive this class. |
| 32 content::WebContents* tab_; |
| 33 |
| 34 // The actual view of the color chooser. No ownership because its parent |
| 35 // view will take care of its lifetime. |
| 36 views::ColorChooserView* view_; |
| 37 |
| 38 // The widget for the color chooser. No ownership because it's released |
| 39 // automatically when closed. |
| 40 views::Widget* widget_; |
| 41 |
| 42 DISALLOW_COPY_AND_ASSIGN(ColorChooserAura); |
| 43 }; |
| 44 |
| 45 ColorChooserAura::ColorChooserAura(int identifier, |
| 46 content::WebContents* tab, |
| 47 SkColor initial_color) |
| 48 : ColorChooser(identifier), |
| 49 tab_(tab) { |
| 50 view_ = new views::ColorChooserView(this, initial_color); |
| 51 widget_ = views::Widget::CreateWindow(view_); |
| 52 widget_->SetAlwaysOnTop(true); |
| 53 widget_->Show(); |
| 54 } |
| 55 |
| 56 void ColorChooserAura::OnColorChosen(SkColor color) { |
| 57 if (tab_) |
| 58 tab_->DidChooseColorInColorChooser(identifier(), color); |
| 59 } |
| 60 |
| 61 void ColorChooserAura::OnColorChooserDialogClosed() { |
| 62 if (tab_) |
| 63 tab_->DidEndColorChooser(identifier()); |
| 64 view_ = NULL; |
| 65 widget_ = NULL; |
| 66 } |
| 67 |
| 68 void ColorChooserAura::End() { |
| 69 if (widget_ && widget_->IsVisible()) { |
| 70 widget_->Close(); |
| 71 view_ = NULL; |
| 72 widget_ = NULL; |
| 73 } |
| 74 } |
| 75 |
| 76 void ColorChooserAura::SetSelectedColor(SkColor color) { |
| 77 if (view_) |
| 78 view_->OnColorChanged(color); |
| 79 } |
| 80 |
| 81 } // namespace |
8 | 82 |
9 // static | 83 // static |
10 content::ColorChooser* content::ColorChooser::Create( | 84 content::ColorChooser* content::ColorChooser::Create( |
11 int identifier, content::WebContents* tab, SkColor initial_color) { | 85 int identifier, content::WebContents* tab, SkColor initial_color) { |
12 NOTIMPLEMENTED(); | 86 return new ColorChooserAura(identifier, tab, initial_color); |
13 return NULL; | |
14 } | 87 } |
OLD | NEW |