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