Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2011 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/color_select_observer.h" | |
| 6 | |
| 7 #include "chrome/browser/platform_util.h" | |
| 8 #include "content/browser/renderer_host/render_view_host.h" | |
| 9 #include "content/browser/renderer_host/render_widget_host_view.h" | |
| 10 #include "content/browser/tab_contents/tab_contents.h" | |
| 11 #include "content/common/view_messages.h" | |
|
jam
2012/01/17 06:49:55
chrome can't include view_messages.h, since that's
keishi
2012/01/27 04:34:08
Done. I've made it go through TabContents and Brow
| |
| 12 | |
| 13 bool ColorSelectObserver::OnMessageReceived(const IPC::Message& message) { | |
| 14 bool handled = true; | |
| 15 IPC_BEGIN_MESSAGE_MAP(ColorSelectObserver, message) | |
| 16 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenColorChooser, OnOpenColorChooser) | |
| 17 IPC_MESSAGE_HANDLER(ViewHostMsg_EndColorChooser, OnEndColorChooser) | |
| 18 IPC_MESSAGE_HANDLER(ViewHostMsg_SetSelectedColorInColorChooser, | |
| 19 OnSetSelectedColorInColorChooser) | |
| 20 IPC_MESSAGE_UNHANDLED(handled = false) | |
| 21 IPC_END_MESSAGE_MAP() | |
| 22 | |
| 23 return handled; | |
| 24 } | |
| 25 | |
| 26 ColorSelectObserver::ColorSelectObserver(content::WebContents* web_contents) | |
| 27 : WebContentsObserver(web_contents) { | |
| 28 } | |
| 29 | |
| 30 ColorSelectObserver::~ColorSelectObserver() { | |
| 31 } | |
| 32 | |
| 33 void ColorSelectObserver::OnOpenColorChooser( | |
| 34 const ViewHostMsg_SetSelectedColorInColorChooser_Params& params) { | |
| 35 render_view_host_ = web_contents()->GetRenderViewHost(); | |
| 36 #if defined(OS_WIN) | |
|
Peter Kasting
2012/01/17 20:53:10
As Ben noted, we shouldn't have bunches of #ifdefs
keishi
2012/01/27 04:34:08
Done.
| |
| 37 if (color_chooser_dialog_) | |
| 38 return; | |
| 39 gfx::NativeWindow owning_window = | |
| 40 platform_util::GetTopLevel(render_view_host_->view()->GetNativeView()); | |
| 41 color_chooser_dialog_ = ColorChooserDialog::Create(this); | |
| 42 color_chooser_dialog_->SelectColor(params.color, owning_window); | |
| 43 #else | |
| 44 ColorChooser::GetInstance()->open(this, params.color); | |
| 45 #endif | |
| 46 } | |
| 47 | |
| 48 void ColorSelectObserver::OnEndColorChooser() { | |
| 49 #if !defined(OS_WIN) | |
| 50 if (render_view_host_ != web_contents()->GetRenderViewHost()) | |
| 51 return; | |
| 52 ColorChooser::GetInstance()->end(this); | |
| 53 #endif | |
| 54 } | |
| 55 | |
| 56 void ColorSelectObserver::OnSetSelectedColorInColorChooser( | |
| 57 const ViewHostMsg_SetSelectedColorInColorChooser_Params& params) { | |
| 58 #if !defined(OS_WIN) | |
| 59 ColorChooser::GetInstance()->setSelectedColor(params.color); | |
| 60 #endif | |
| 61 } | |
| 62 | |
| 63 void ColorSelectObserver::DidChooseColor(WebKit::WebColor color) { | |
| 64 render_view_host_->DidChooseColorInColorChooser(color); | |
| 65 } | |
| 66 | |
| 67 void ColorSelectObserver::DidEnd() { | |
| 68 render_view_host_->DidEndColorChooser(); | |
| 69 #if defined(OS_WIN) | |
| 70 color_chooser_dialog_ = 0; | |
| 71 #endif | |
| 72 } | |
| OLD | NEW |