Home | History | Annotate | Download | only in views
      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
      3 // found in the LICENSE file.
      4 
      5 #include "chrome/browser/ui/views/color_chooser_aura.h"
      6 
      7 #include "chrome/browser/ui/browser_dialogs.h"
      8 #include "chrome/browser/ui/browser_finder.h"
      9 #include "chrome/browser/ui/browser_window.h"
     10 #include "content/public/browser/web_contents.h"
     11 #include "ui/views/color_chooser/color_chooser_view.h"
     12 #include "ui/views/widget/widget.h"
     13 
     14 ColorChooserAura::ColorChooserAura(content::WebContents* web_contents,
     15                                    SkColor initial_color)
     16     : web_contents_(web_contents) {
     17   view_ = new views::ColorChooserView(this, initial_color);
     18   widget_ = views::Widget::CreateWindowWithParent(
     19       view_, web_contents->GetTopLevelNativeWindow());
     20   widget_->Show();
     21 }
     22 
     23 void ColorChooserAura::OnColorChosen(SkColor color) {
     24   if (web_contents_)
     25     web_contents_->DidChooseColorInColorChooser(color);
     26 }
     27 
     28 void ColorChooserAura::OnColorChooserDialogClosed() {
     29   view_ = NULL;
     30   widget_ = NULL;
     31   DidEndColorChooser();
     32 }
     33 
     34 void ColorChooserAura::End() {
     35   if (widget_) {
     36     view_->set_listener(NULL);
     37     widget_->Close();
     38     view_ = NULL;
     39     widget_ = NULL;
     40     // DidEndColorChooser will invoke Browser::DidEndColorChooser, which deletes
     41     // this. Take care of the call order.
     42     DidEndColorChooser();
     43   }
     44 }
     45 
     46 void ColorChooserAura::DidEndColorChooser() {
     47   if (web_contents_)
     48     web_contents_->DidEndColorChooser();
     49 }
     50 
     51 void ColorChooserAura::SetSelectedColor(SkColor color) {
     52   if (view_)
     53     view_->OnColorChanged(color);
     54 }
     55 
     56 // static
     57 ColorChooserAura* ColorChooserAura::Open(
     58     content::WebContents* web_contents, SkColor initial_color) {
     59   return new ColorChooserAura(web_contents, initial_color);
     60 }
     61 
     62 #if !defined(OS_WIN)
     63 namespace chrome {
     64 
     65 content::ColorChooser* ShowColorChooser(content::WebContents* web_contents,
     66                                         SkColor initial_color) {
     67   return ColorChooserAura::Open(web_contents, initial_color);
     68 }
     69 
     70 }  // namespace chrome
     71 #endif  // OS_WIN
     72