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/frame_messages.h"
11 static int GenerateColorChooserIdentifier() {
16 RendererWebColorChooserImpl::RendererWebColorChooserImpl(
17 RenderFrame
* render_frame
,
18 blink::WebColorChooserClient
* client
)
19 : RenderFrameObserver(render_frame
),
20 identifier_(GenerateColorChooserIdentifier()),
24 RendererWebColorChooserImpl::~RendererWebColorChooserImpl() {
27 bool RendererWebColorChooserImpl::OnMessageReceived(
28 const IPC::Message
& message
) {
30 IPC_BEGIN_MESSAGE_MAP(RendererWebColorChooserImpl
, message
)
31 IPC_MESSAGE_HANDLER(FrameMsg_DidChooseColorResponse
,
32 OnDidChooseColorResponse
)
33 IPC_MESSAGE_HANDLER(FrameMsg_DidEndColorChooser
, OnDidEndColorChooser
)
34 IPC_MESSAGE_UNHANDLED(handled
= false)
39 void RendererWebColorChooserImpl::setSelectedColor(blink::WebColor color
) {
40 Send(new FrameHostMsg_SetSelectedColorInColorChooser(
41 routing_id(), identifier_
, static_cast<SkColor
>(color
)));
44 void RendererWebColorChooserImpl::endChooser() {
45 Send(new FrameHostMsg_EndColorChooser(routing_id(), identifier_
));
48 void RendererWebColorChooserImpl::Open(
49 SkColor initial_color
,
50 const std::vector
<content::ColorSuggestion
>& suggestions
) {
51 Send(new FrameHostMsg_OpenColorChooser(routing_id(),
57 void RendererWebColorChooserImpl::OnDidChooseColorResponse(int color_chooser_id
,
59 DCHECK(identifier_
== color_chooser_id
);
61 client_
->didChooseColor(static_cast<blink::WebColor
>(color
));
64 void RendererWebColorChooserImpl::OnDidEndColorChooser(int color_chooser_id
) {
65 if (identifier_
!= color_chooser_id
)
67 client_
->didEndChooser();
70 } // namespace content