OLD | NEW |
(Empty) | |
| 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 "content/renderer/renderer_webcolorchooser_impl.h" |
| 6 |
| 7 #include "content/common/view_messages.h" |
| 8 #include "content/renderer/render_view_impl.h" |
| 9 |
| 10 static int GenerateColorChooserIdentifier() { |
| 11 static int next = 0; |
| 12 return ++next; |
| 13 } |
| 14 |
| 15 RendererWebColorChooserImpl::RendererWebColorChooserImpl( |
| 16 RenderViewImpl* render_view, |
| 17 WebKit::WebColorChooserClient* client) |
| 18 : content::RenderViewObserver(render_view), |
| 19 identifier_(GenerateColorChooserIdentifier()), |
| 20 client_(client) { |
| 21 } |
| 22 |
| 23 RendererWebColorChooserImpl::~RendererWebColorChooserImpl() { |
| 24 } |
| 25 |
| 26 bool RendererWebColorChooserImpl::OnMessageReceived( |
| 27 const IPC::Message& message) { |
| 28 bool handled = true; |
| 29 IPC_BEGIN_MESSAGE_MAP(RendererWebColorChooserImpl, message) |
| 30 IPC_MESSAGE_HANDLER(ViewMsg_DidChooseColorResponse, |
| 31 OnDidChooseColorResponse) |
| 32 IPC_MESSAGE_HANDLER(ViewMsg_DidEndColorChooser, |
| 33 OnDidEndColorChooser) |
| 34 IPC_MESSAGE_UNHANDLED(handled = false) |
| 35 IPC_END_MESSAGE_MAP() |
| 36 return handled; |
| 37 } |
| 38 |
| 39 void RendererWebColorChooserImpl::FrameWillClose(WebKit::WebFrame* frame) { |
| 40 endChooser(); |
| 41 client_->didEndChooser(); |
| 42 } |
| 43 |
| 44 void RendererWebColorChooserImpl::setSelectedColor(WebKit::WebColor color) { |
| 45 Send(new ViewHostMsg_SetSelectedColorInColorChooser(routing_id(), identifier_, |
| 46 static_cast<SkColor>(color))); |
| 47 } |
| 48 |
| 49 void RendererWebColorChooserImpl::endChooser() { |
| 50 Send(new ViewHostMsg_EndColorChooser(routing_id(), identifier_)); |
| 51 } |
| 52 |
| 53 void RendererWebColorChooserImpl::Open(SkColor initial_color) { |
| 54 Send(new ViewHostMsg_OpenColorChooser(routing_id(), identifier_, |
| 55 initial_color)); |
| 56 } |
| 57 |
| 58 void RendererWebColorChooserImpl::OnDidChooseColorResponse( |
| 59 int color_chooser_id, |
| 60 const SkColor& color) { |
| 61 DCHECK(identifier_ == color_chooser_id); |
| 62 |
| 63 client_->didChooseColor(static_cast<WebKit::WebColor>(color)); |
| 64 } |
| 65 |
| 66 void RendererWebColorChooserImpl::OnDidEndColorChooser(int color_chooser_id) { |
| 67 if (identifier_ != color_chooser_id) |
| 68 return; |
| 69 client_->didEndChooser(); |
| 70 } |
OLD | NEW |