Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / content / renderer / renderer_webcolorchooser_impl.cc
blobea0b14da4dafe951098f60bdff63e61bb385828a
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"
9 namespace content {
11 static int GenerateColorChooserIdentifier() {
12 static int next = 0;
13 return ++next;
16 RendererWebColorChooserImpl::RendererWebColorChooserImpl(
17 RenderFrame* render_frame,
18 blink::WebColorChooserClient* client)
19 : RenderFrameObserver(render_frame),
20 identifier_(GenerateColorChooserIdentifier()),
21 client_(client) {
24 RendererWebColorChooserImpl::~RendererWebColorChooserImpl() {
27 bool RendererWebColorChooserImpl::OnMessageReceived(
28 const IPC::Message& message) {
29 bool handled = true;
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)
35 IPC_END_MESSAGE_MAP()
36 return handled;
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(),
52 identifier_,
53 initial_color,
54 suggestions));
57 void RendererWebColorChooserImpl::OnDidChooseColorResponse(int color_chooser_id,
58 SkColor color) {
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)
66 return;
67 client_->didEndChooser();
70 } // namespace content