Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 Google Inc. All rights reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions |
| 6 | * are met: |
| 7 | * |
| 8 | * 1. Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * 2. Redistributions in binary form must reproduce the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer in the |
| 12 | * documentation and/or other materials provided with the distribution. |
| 13 | * |
| 14 | * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY |
| 15 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 16 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 17 | * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY |
| 18 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 19 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 20 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 21 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 | */ |
| 25 | |
| 26 | #include "config.h" |
| 27 | #include "ColorChooserUIController.h" |
| 28 | |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 29 | #include "ChromeClientImpl.h" |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 30 | #include "WebColorChooser.h" |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 31 | #include "WebColorSuggestion.h" |
| 32 | #include "WebViewClient.h" |
| 33 | #include "WebViewImpl.h" |
Torne (Richard Coles) | 19cde67 | 2013-11-06 12:28:04 +0000 | [diff] [blame] | 34 | #include "platform/ColorChooserClient.h" |
Torne (Richard Coles) | f79f16f | 2013-10-31 11:16:44 +0000 | [diff] [blame] | 35 | #include "platform/graphics/Color.h" |
Torne (Richard Coles) | 5267f70 | 2013-06-11 10:57:24 +0100 | [diff] [blame] | 36 | #include "public/platform/WebColor.h" |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 37 | |
| 38 | using namespace WebCore; |
| 39 | |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 40 | namespace blink { |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 41 | |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 42 | |
| 43 | ColorChooserUIController::ColorChooserUIController(ChromeClientImpl* chromeClient, ColorChooserClient* client) |
| 44 | : m_chromeClient(chromeClient) |
| 45 | , m_client(client) |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 46 | { |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | ColorChooserUIController::~ColorChooserUIController() |
| 50 | { |
| 51 | } |
| 52 | |
Torne (Richard Coles) | 926b001 | 2013-03-28 15:32:48 +0000 | [diff] [blame] | 53 | void ColorChooserUIController::openUI() |
| 54 | { |
| 55 | openColorChooser(); |
| 56 | } |
| 57 | |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 58 | void ColorChooserUIController::setSelectedColor(const Color& color) |
| 59 | { |
| 60 | ASSERT(m_chooser); |
| 61 | m_chooser->setSelectedColor(static_cast<WebColor>(color.rgb())); |
| 62 | } |
| 63 | |
| 64 | void ColorChooserUIController::endChooser() |
| 65 | { |
| 66 | if (m_chooser) |
| 67 | m_chooser->endChooser(); |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | void ColorChooserUIController::didChooseColor(const WebColor& color) |
| 71 | { |
| 72 | ASSERT(m_client); |
| 73 | m_client->didChooseColor(Color(static_cast<RGBA32>(color))); |
| 74 | } |
| 75 | |
| 76 | void ColorChooserUIController::didEndChooser() |
| 77 | { |
| 78 | ASSERT(m_client); |
| 79 | m_chooser = nullptr; |
| 80 | m_client->didEndChooser(); |
| 81 | } |
| 82 | |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 83 | void ColorChooserUIController::openColorChooser() |
| 84 | { |
| 85 | ASSERT(!m_chooser); |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 86 | WebViewClient* webViewClient = static_cast<WebViewImpl*>(m_chromeClient->webView())->client(); |
| 87 | if (!webViewClient) |
| 88 | return; |
| 89 | m_chooser = adoptPtr(webViewClient->createColorChooser(this, static_cast<WebColor>(m_client->currentColor().rgb()))); |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 90 | } |
| 91 | |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 92 | } // namespace blink |