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" |
| 12 |
| 13 #if defined(ENABLE_INPUT_COLOR) |
| 14 |
| 15 bool ColorSelectObserver::OnMessageReceived(const IPC::Message& message) { |
| 16 bool handled = true; |
| 17 IPC_BEGIN_MESSAGE_MAP(ColorSelectObserver, message) |
| 18 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenColorChooser, OnOpenColorChooser) |
| 19 IPC_MESSAGE_HANDLER(ViewHostMsg_DetachColorChooser, OnDetachColorChooser) |
| 20 IPC_MESSAGE_HANDLER(ViewHostMsg_SetSelectedColorInColorChooser, |
| 21 OnSetSelectedColorInColorChooser) |
| 22 IPC_MESSAGE_UNHANDLED(handled = false) |
| 23 IPC_END_MESSAGE_MAP() |
| 24 |
| 25 return handled; |
| 26 } |
| 27 |
| 28 ColorSelectObserver::ColorSelectObserver(content::WebContents* web_contents) |
| 29 : WebContentsObserver(web_contents) { |
| 30 } |
| 31 |
| 32 ColorSelectObserver::~ColorSelectObserver() { |
| 33 } |
| 34 |
| 35 void ColorSelectObserver::OnOpenColorChooser( |
| 36 const ViewHostMsg_SetSelectedColorInColorChooser_Params& params) { |
| 37 render_view_host_ = web_contents()->GetRenderViewHost(); |
| 38 #if defined(OS_WIN) |
| 39 if (color_chooser_dialog_) |
| 40 return; |
| 41 gfx::NativeWindow owning_window = |
| 42 platform_util::GetTopLevel(render_view_host_->view()->GetNativeView()); |
| 43 color_chooser_dialog_ = ColorChooserDialog::Create(this); |
| 44 color_chooser_dialog_->SelectColor(params.color, owning_window); |
| 45 #else |
| 46 ColorChooser::GetInstance()->open(this, params.color); |
| 47 #endif |
| 48 } |
| 49 |
| 50 void ColorSelectObserver::OnDetachColorChooser() { |
| 51 #if !defined(OS_WIN) |
| 52 if (render_view_host_ != web_contents()->GetRenderViewHost()) |
| 53 return; |
| 54 ColorChooser::GetInstance()->detach(this); |
| 55 #endif |
| 56 } |
| 57 |
| 58 void ColorSelectObserver::OnSetSelectedColorInColorChooser( |
| 59 const ViewHostMsg_SetSelectedColorInColorChooser_Params& params) { |
| 60 #if !defined(OS_WIN) |
| 61 ColorChooser::GetInstance()->setSelectedColor(params.color); |
| 62 #endif |
| 63 } |
| 64 |
| 65 void ColorSelectObserver::DidChooseColor(WebKit::WebColor color) { |
| 66 render_view_host_->DidChooseColorInColorChooser(color); |
| 67 } |
| 68 |
| 69 void ColorSelectObserver::DidDetach() { |
| 70 render_view_host_->DidDetachColorChooser(); |
| 71 #if defined(OS_WIN) |
| 72 color_chooser_dialog_ = 0; |
| 73 #endif |
| 74 } |
| 75 |
| 76 #endif // defined(ENABLE_INPUT_COLOR) |
OLD | NEW |