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.
5 #include "content/renderer/renderer_webcolorchooser_impl.h"
7 #include "content/common/view_messages.h"
8 #include "content/renderer/render_view_impl.h"
12 static int GenerateColorChooserIdentifier() {
17 RendererWebColorChooserImpl::RendererWebColorChooserImpl(
18 RenderViewImpl* render_view,
19 WebKit::WebColorChooserClient* client)
20 : RenderViewObserver(render_view),
21 identifier_(GenerateColorChooserIdentifier()),
25 RendererWebColorChooserImpl::~RendererWebColorChooserImpl() {
28 bool RendererWebColorChooserImpl::OnMessageReceived(
29 const IPC::Message& message) {
31 IPC_BEGIN_MESSAGE_MAP(RendererWebColorChooserImpl, message)
32 IPC_MESSAGE_HANDLER(ViewMsg_DidChooseColorResponse,
33 OnDidChooseColorResponse)
34 IPC_MESSAGE_HANDLER(ViewMsg_DidEndColorChooser,
36 IPC_MESSAGE_UNHANDLED(handled = false)
41 void RendererWebColorChooserImpl::setSelectedColor(WebKit::WebColor color) {
42 Send(new ViewHostMsg_SetSelectedColorInColorChooser(routing_id(), identifier_,
43 static_cast<SkColor>(color)));
46 void RendererWebColorChooserImpl::endChooser() {
47 Send(new ViewHostMsg_EndColorChooser(routing_id(), identifier_));
50 void RendererWebColorChooserImpl::Open(SkColor initial_color) {
51 Send(new ViewHostMsg_OpenColorChooser(routing_id(), identifier_,
55 void RendererWebColorChooserImpl::OnDidChooseColorResponse(int color_chooser_id,
57 DCHECK(identifier_ == color_chooser_id);
59 client_->didChooseColor(static_cast<WebKit::WebColor>(color));
62 void RendererWebColorChooserImpl::OnDidEndColorChooser(int color_chooser_id) {
63 if (identifier_ != color_chooser_id)
65 client_->didEndChooser();
68 } // namespace content