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