diff options
39 files changed, 533 insertions, 231 deletions
diff --git a/apps/shell_window.cc b/apps/shell_window.cc index 75cd7cd..ada3c81 100644 --- a/apps/shell_window.cc +++ b/apps/shell_window.cc @@ -613,8 +613,10 @@ bool ShellWindow::ShouldSuppressDialogs() { return true; } -content::ColorChooser* ShellWindow::OpenColorChooser(WebContents* web_contents, - SkColor initial_color) { +content::ColorChooser* ShellWindow::OpenColorChooser( + WebContents* web_contents, + SkColor initial_color, + const std::vector<content::ColorSuggestion>& suggestionss) { return delegate_->ShowColorChooser(web_contents, initial_color); } diff --git a/apps/shell_window.h b/apps/shell_window.h index e833f75..584c612 100644 --- a/apps/shell_window.h +++ b/apps/shell_window.h @@ -347,7 +347,9 @@ class ShellWindow : public content::NotificationObserver, virtual void CloseContents(content::WebContents* contents) OVERRIDE; virtual bool ShouldSuppressDialogs() OVERRIDE; virtual content::ColorChooser* OpenColorChooser( - content::WebContents* web_contents, SkColor color) OVERRIDE; + content::WebContents* web_contents, + SkColor color, + const std::vector<content::ColorSuggestion>& suggestions) OVERRIDE; virtual void RunFileChooser( content::WebContents* tab, const content::FileChooserParams& params) OVERRIDE; diff --git a/chrome/browser/devtools/devtools_window.cc b/chrome/browser/devtools/devtools_window.cc index d9f5616..75b98c1 100644 --- a/chrome/browser/devtools/devtools_window.cc +++ b/chrome/browser/devtools/devtools_window.cc @@ -948,7 +948,8 @@ content::JavaScriptDialogManager* DevToolsWindow::GetJavaScriptDialogManager() { content::ColorChooser* DevToolsWindow::OpenColorChooser( content::WebContents* web_contents, - SkColor initial_color) { + SkColor initial_color, + const std::vector<content::ColorSuggestion>& suggestions) { return chrome::ShowColorChooser(web_contents, initial_color); } diff --git a/chrome/browser/devtools/devtools_window.h b/chrome/browser/devtools/devtools_window.h index b99ff1f..ce8bcee 100644 --- a/chrome/browser/devtools/devtools_window.h +++ b/chrome/browser/devtools/devtools_window.h @@ -261,7 +261,8 @@ class DevToolsWindow : private content::NotificationObserver, GetJavaScriptDialogManager() OVERRIDE; virtual content::ColorChooser* OpenColorChooser( content::WebContents* web_contents, - SkColor color) OVERRIDE; + SkColor color, + const std::vector<content::ColorSuggestion>& suggestions) OVERRIDE; virtual void RunFileChooser( content::WebContents* web_contents, const content::FileChooserParams& params) OVERRIDE; diff --git a/chrome/browser/extensions/extension_host.cc b/chrome/browser/extensions/extension_host.cc index c76aced..46ba15f 100644 --- a/chrome/browser/extensions/extension_host.cc +++ b/chrome/browser/extensions/extension_host.cc @@ -499,7 +499,9 @@ content::JavaScriptDialogManager* ExtensionHost::GetJavaScriptDialogManager() { } content::ColorChooser* ExtensionHost::OpenColorChooser( - WebContents* web_contents, SkColor initial_color) { + WebContents* web_contents, + SkColor initial_color, + const std::vector<content::ColorSuggestion>& suggestions) { return chrome::ShowColorChooser(web_contents, initial_color); } diff --git a/chrome/browser/extensions/extension_host.h b/chrome/browser/extensions/extension_host.h index f04ea01..9222d15 100644 --- a/chrome/browser/extensions/extension_host.h +++ b/chrome/browser/extensions/extension_host.h @@ -104,7 +104,9 @@ class ExtensionHost : public content::WebContentsDelegate, virtual content::JavaScriptDialogManager* GetJavaScriptDialogManager() OVERRIDE; virtual content::ColorChooser* OpenColorChooser( - content::WebContents* web_contents, SkColor color) OVERRIDE; + content::WebContents* web_contents, + SkColor color, + const std::vector<content::ColorSuggestion>& suggestions) OVERRIDE; virtual void RunFileChooser( content::WebContents* tab, const content::FileChooserParams& params) OVERRIDE; diff --git a/chrome/browser/ui/browser.cc b/chrome/browser/ui/browser.cc index c618f43..9a52aa8 100644 --- a/chrome/browser/ui/browser.cc +++ b/chrome/browser/ui/browser.cc @@ -1596,8 +1596,10 @@ content::JavaScriptDialogManager* Browser::GetJavaScriptDialogManager() { return GetJavaScriptDialogManagerInstance(); } -content::ColorChooser* Browser::OpenColorChooser(WebContents* web_contents, - SkColor initial_color) { +content::ColorChooser* Browser::OpenColorChooser( + WebContents* web_contents, + SkColor initial_color, + const std::vector<content::ColorSuggestion>& suggestions) { return chrome::ShowColorChooser(web_contents, initial_color); } @@ -2270,7 +2272,6 @@ bool Browser::MaybeCreateBackgroundContents( return true; // For scriptable background pages, if one already exists, close it (even // if it was specified in the manifest). - DLOG(INFO) << "Closing existing BackgroundContents for " << opener_url; delete existing; } diff --git a/chrome/browser/ui/browser.h b/chrome/browser/ui/browser.h index 3af23d2..b53ee9e 100644 --- a/chrome/browser/ui/browser.h +++ b/chrome/browser/ui/browser.h @@ -615,7 +615,9 @@ class Browser : public TabStripModelObserver, virtual content::JavaScriptDialogManager* GetJavaScriptDialogManager() OVERRIDE; virtual content::ColorChooser* OpenColorChooser( - content::WebContents* web_contents, SkColor color) OVERRIDE; + content::WebContents* web_contents, + SkColor color, + const std::vector<content::ColorSuggestion>& suggestions) OVERRIDE; virtual void RunFileChooser( content::WebContents* web_contents, const content::FileChooserParams& params) OVERRIDE; diff --git a/chrome/browser/ui/views/external_tab_container_win.cc b/chrome/browser/ui/views/external_tab_container_win.cc index 189016d..aae3926 100644 --- a/chrome/browser/ui/views/external_tab_container_win.cc +++ b/chrome/browser/ui/views/external_tab_container_win.cc @@ -995,7 +995,9 @@ void ExternalTabContainerWin::ShowRepostFormWarningDialog(WebContents* source) { } content::ColorChooser* ExternalTabContainerWin::OpenColorChooser( - WebContents* web_contents, SkColor initial_color) { + WebContents* web_contents, + SkColor initial_color, + const std::vector<content::ColorSuggestion>& suggestions) { return chrome::ShowColorChooser(web_contents, initial_color); } diff --git a/chrome/browser/ui/views/external_tab_container_win.h b/chrome/browser/ui/views/external_tab_container_win.h index 71633765..aea627d 100644 --- a/chrome/browser/ui/views/external_tab_container_win.h +++ b/chrome/browser/ui/views/external_tab_container_win.h @@ -144,7 +144,9 @@ class ExternalTabContainerWin : public ExternalTabContainer, virtual void ShowRepostFormWarningDialog( content::WebContents* source) OVERRIDE; virtual content::ColorChooser* OpenColorChooser( - content::WebContents* web_contents, SkColor color) OVERRIDE; + content::WebContents* web_contents, + SkColor color, + const std::vector<content::ColorSuggestion>& suggestions) OVERRIDE; virtual void RunFileChooser( content::WebContents* tab, const content::FileChooserParams& params) OVERRIDE; diff --git a/components/web_contents_delegate_android/android/java/src/org/chromium/components/web_contents_delegate_android/ColorChooserAndroid.java b/components/web_contents_delegate_android/android/java/src/org/chromium/components/web_contents_delegate_android/ColorChooserAndroid.java index babf91e..e52bd04 100644 --- a/components/web_contents_delegate_android/android/java/src/org/chromium/components/web_contents_delegate_android/ColorChooserAndroid.java +++ b/components/web_contents_delegate_android/android/java/src/org/chromium/components/web_contents_delegate_android/ColorChooserAndroid.java @@ -9,6 +9,7 @@ import android.content.Context; import org.chromium.base.CalledByNative; import org.chromium.base.JNINamespace; import org.chromium.content.browser.ContentViewCore; +import org.chromium.ui.ColorSuggestion; import org.chromium.ui.ColorPickerDialog; import org.chromium.ui.OnColorChangedListener; @@ -22,7 +23,7 @@ public class ColorChooserAndroid { private final int mNativeColorChooserAndroid; private ColorChooserAndroid(int nativeColorChooserAndroid, - Context context, int initialColor) { + Context context, int initialColor, ColorSuggestion[] suggestions) { OnColorChangedListener listener = new OnColorChangedListener() { @Override public void onColorChanged(int color) { @@ -32,7 +33,7 @@ public class ColorChooserAndroid { }; mNativeColorChooserAndroid = nativeColorChooserAndroid; - mDialog = new ColorPickerDialog(context, listener, initialColor); + mDialog = new ColorPickerDialog(context, listener, initialColor, suggestions); } private void openColorChooser() { @@ -48,13 +49,31 @@ public class ColorChooserAndroid { public static ColorChooserAndroid createColorChooserAndroid( int nativeColorChooserAndroid, ContentViewCore contentViewCore, - int initialColor) { + int initialColor, + ColorSuggestion[] suggestions) { ColorChooserAndroid chooser = new ColorChooserAndroid(nativeColorChooserAndroid, - contentViewCore.getContext(), initialColor); + contentViewCore.getContext(), initialColor, suggestions); chooser.openColorChooser(); return chooser; } + @CalledByNative + private static ColorSuggestion[] createColorSuggestionArray(int size) { + return new ColorSuggestion[size]; + } + + /** + * @param array ColorSuggestion array that should get a new suggestion added. + * @param index Index in the array where to place a new suggestion. + * @param color Color of the suggestion. + * @param label Label of the suggestion. + */ + @CalledByNative + private static void addToColorSuggestionArray(ColorSuggestion[] array, int index, + int color, String label) { + array[index] = new ColorSuggestion(color, label); + } + // Implemented in color_chooser_android.cc private native void nativeOnColorChosen(int nativeColorChooserAndroid, int color); } diff --git a/components/web_contents_delegate_android/color_chooser_android.cc b/components/web_contents_delegate_android/color_chooser_android.cc index 4eb3d03..a1dcf40 100644 --- a/components/web_contents_delegate_android/color_chooser_android.cc +++ b/components/web_contents_delegate_android/color_chooser_android.cc @@ -4,26 +4,52 @@ #include "components/web_contents_delegate_android/color_chooser_android.h" +#include "base/android/jni_array.h" +#include "base/android/jni_string.h" #include "content/public/browser/android/content_view_core.h" #include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents_view.h" +#include "content/public/common/color_suggestion.h" #include "jni/ColorChooserAndroid_jni.h" +using base::android::ConvertUTF16ToJavaString; + namespace web_contents_delegate_android { -ColorChooserAndroid::ColorChooserAndroid(content::WebContents* web_contents, - SkColor initial_color) +ColorChooserAndroid::ColorChooserAndroid( + content::WebContents* web_contents, + SkColor initial_color, + const std::vector<content::ColorSuggestion>& suggestions) : web_contents_(web_contents) { JNIEnv* env = AttachCurrentThread(); content::ContentViewCore* content_view_core = content::ContentViewCore::FromWebContents(web_contents); DCHECK(content_view_core); + ScopedJavaLocalRef<jobjectArray> suggestions_array; + + if (suggestions.size() > 0) { + suggestions_array = Java_ColorChooserAndroid_createColorSuggestionArray( + env, suggestions.size()); + + for (size_t i = 0; i < suggestions.size(); ++i) { + const content::ColorSuggestion& suggestion = suggestions[i]; + ScopedJavaLocalRef<jstring> label = ConvertUTF16ToJavaString( + env, suggestion.label); + Java_ColorChooserAndroid_addToColorSuggestionArray( + env, + suggestions_array.obj(), + i, + suggestion.color, + label.obj()); + } + } j_color_chooser_.Reset(Java_ColorChooserAndroid_createColorChooserAndroid( env, reinterpret_cast<intptr_t>(this), content_view_core->GetJavaObject().obj(), - initial_color)); + initial_color, + suggestions_array.obj())); } ColorChooserAndroid::~ColorChooserAndroid() { diff --git a/components/web_contents_delegate_android/color_chooser_android.h b/components/web_contents_delegate_android/color_chooser_android.h index 8ab3326..eefd85b 100644 --- a/components/web_contents_delegate_android/color_chooser_android.h +++ b/components/web_contents_delegate_android/color_chooser_android.h @@ -5,9 +5,11 @@ #ifndef COMPONENTS_WEB_CONTENTS_DELEGATE_ANDROID_COLOR_CHOOSER_ANDROID_H_ #define COMPONENTS_WEB_CONTENTS_DELEGATE_ANDROID_COLOR_CHOOSER_ANDROID_H_ +#include <vector> #include "base/android/jni_android.h" #include "base/basictypes.h" #include "base/compiler_specific.h" +#include "base/strings/string16.h" #include "content/public/browser/color_chooser.h" using base::android::AttachCurrentThread; @@ -15,6 +17,7 @@ using base::android::ScopedJavaLocalRef; namespace content { class WebContents; +struct ColorSuggestion; } namespace web_contents_delegate_android { @@ -23,7 +26,8 @@ namespace web_contents_delegate_android { class ColorChooserAndroid : public content::ColorChooser { public: ColorChooserAndroid(content::WebContents* tab, - SkColor initial_color); + SkColor initial_color, + const std::vector<content::ColorSuggestion>& suggestions); virtual ~ColorChooserAndroid(); void OnColorChosen(JNIEnv* env, jobject obj, jint color); diff --git a/components/web_contents_delegate_android/web_contents_delegate_android.cc b/components/web_contents_delegate_android/web_contents_delegate_android.cc index 6b233dc..1474e60 100644 --- a/components/web_contents_delegate_android/web_contents_delegate_android.cc +++ b/components/web_contents_delegate_android/web_contents_delegate_android.cc @@ -50,9 +50,11 @@ WebContentsDelegateAndroid::GetJavaDelegate(JNIEnv* env) const { // WebContentsDelegate methods // ---------------------------------------------------------------------------- -ColorChooser* WebContentsDelegateAndroid::OpenColorChooser(WebContents* source, - SkColor color) { - return new ColorChooserAndroid(source, color); +ColorChooser* WebContentsDelegateAndroid::OpenColorChooser( + WebContents* source, + SkColor color, + const std::vector<content::ColorSuggestion>& suggestions) { + return new ColorChooserAndroid(source, color, suggestions); } // OpenURLFromTab() will be called when we're performing a browser-intiated diff --git a/components/web_contents_delegate_android/web_contents_delegate_android.h b/components/web_contents_delegate_android/web_contents_delegate_android.h index 5e88906..565a1e0 100644 --- a/components/web_contents_delegate_android/web_contents_delegate_android.h +++ b/components/web_contents_delegate_android/web_contents_delegate_android.h @@ -52,8 +52,10 @@ class WebContentsDelegateAndroid : public content::WebContentsDelegate { virtual content::WebContents* OpenURLFromTab( content::WebContents* source, const content::OpenURLParams& params) OVERRIDE; - virtual content::ColorChooser* OpenColorChooser(content::WebContents* source, - SkColor color) OVERRIDE; + virtual content::ColorChooser* OpenColorChooser( + content::WebContents* source, + SkColor color, + const std::vector<content::ColorSuggestion>& suggestions) OVERRIDE; virtual void NavigationStateChanged(const content::WebContents* source, unsigned changed_flags) OVERRIDE; virtual void ActivateContents(content::WebContents* contents) OVERRIDE; diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc index 7f17de7..e05cab0 100644 --- a/content/browser/web_contents/web_contents_impl.cc +++ b/content/browser/web_contents/web_contents_impl.cc @@ -2351,9 +2351,12 @@ void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url, AppCacheAccessed(manifest_url, blocked_by_policy)); } -void WebContentsImpl::OnOpenColorChooser(int color_chooser_id, - SkColor color) { - ColorChooser* new_color_chooser = delegate_->OpenColorChooser(this, color); +void WebContentsImpl::OnOpenColorChooser( + int color_chooser_id, + SkColor color, + const std::vector<ColorSuggestion>& suggestions) { + ColorChooser* new_color_chooser = + delegate_->OpenColorChooser(this, color, suggestions); if (color_chooser_ == new_color_chooser) return; color_chooser_.reset(new_color_chooser); diff --git a/content/browser/web_contents/web_contents_impl.h b/content/browser/web_contents/web_contents_impl.h index 1717077..7229682 100644 --- a/content/browser/web_contents/web_contents_impl.h +++ b/content/browser/web_contents/web_contents_impl.h @@ -65,6 +65,7 @@ class WebContentsImpl; class WebContentsObserver; class WebContentsViewPort; class WebContentsViewDelegate; +struct ColorSuggestion; struct FaviconURL; struct LoadNotificationDetails; @@ -645,7 +646,9 @@ class CONTENT_EXPORT WebContentsImpl void OnCrashedPlugin(const base::FilePath& plugin_path, base::ProcessId plugin_pid); void OnAppCacheAccessed(const GURL& manifest_url, bool blocked_by_policy); - void OnOpenColorChooser(int color_chooser_id, SkColor color); + void OnOpenColorChooser(int color_chooser_id, + SkColor color, + const std::vector<ColorSuggestion>& suggestions); void OnEndColorChooser(int color_chooser_id); void OnSetSelectedColorInColorChooser(int color_chooser_id, SkColor color); void OnPepperPluginHung(int plugin_child_id, diff --git a/content/common/view_messages.h b/content/common/view_messages.h index 7c7c323..0dc7ab8 100644 --- a/content/common/view_messages.h +++ b/content/common/view_messages.h @@ -20,6 +20,7 @@ #include "content/common/view_message_enums.h" #include "content/common/webplugin_geometry.h" #include "content/port/common/input_event_ack_state.h" +#include "content/public/common/color_suggestion.h" #include "content/public/common/common_param_traits.h" #include "content/public/common/context_menu_params.h" #include "content/public/common/favicon_url.h" @@ -159,6 +160,11 @@ IPC_STRUCT_TRAITS_BEGIN(content::MenuItem) IPC_STRUCT_TRAITS_MEMBER(submenu) IPC_STRUCT_TRAITS_END() +IPC_STRUCT_TRAITS_BEGIN(content::ColorSuggestion) + IPC_STRUCT_TRAITS_MEMBER(color) + IPC_STRUCT_TRAITS_MEMBER(label) +IPC_STRUCT_TRAITS_END() + IPC_STRUCT_TRAITS_BEGIN(content::ContextMenuParams) IPC_STRUCT_TRAITS_MEMBER(media_type) IPC_STRUCT_TRAITS_MEMBER(x) @@ -1970,9 +1976,10 @@ IPC_MESSAGE_ROUTED1(ViewHostMsg_SelectionBoundsChanged, ViewHostMsg_SelectionBounds_Params) // Asks the browser to open the color chooser. -IPC_MESSAGE_ROUTED2(ViewHostMsg_OpenColorChooser, +IPC_MESSAGE_ROUTED3(ViewHostMsg_OpenColorChooser, int /* id */, - SkColor /* color */) + SkColor /* color */, + std::vector<content::ColorSuggestion> /* suggestions */) // Asks the browser to end the color chooser. IPC_MESSAGE_ROUTED1(ViewHostMsg_EndColorChooser, int /* id */) diff --git a/content/content_common.gypi b/content/content_common.gypi index 646a46f..d08faea 100644 --- a/content/content_common.gypi +++ b/content/content_common.gypi @@ -9,6 +9,7 @@ '../net/net.gyp:net', '../skia/skia.gyp:skia', '../third_party/icu/icu.gyp:icuuc', + '../third_party/WebKit/public/blink.gyp:blink', '../ui/gfx/gfx.gyp:gfx', '../ui/shell_dialogs/shell_dialogs.gyp:shell_dialogs', '../ui/ui.gyp:ui', @@ -27,6 +28,8 @@ 'public/common/child_process_host_delegate.cc', 'public/common/child_process_host_delegate.h', 'public/common/child_process_sandbox_support_linux.h', + 'public/common/color_suggestion.cc', + 'public/common/color_suggestion.h', 'public/common/content_constants.cc', 'public/common/content_constants.h', 'public/common/content_descriptors.h', diff --git a/content/public/browser/web_contents_delegate.cc b/content/public/browser/web_contents_delegate.cc index 3e0329b..f9e4951 100644 --- a/content/public/browser/web_contents_delegate.cc +++ b/content/public/browser/web_contents_delegate.cc @@ -146,7 +146,9 @@ bool WebContentsDelegate::IsFullscreenForTabOrPending( } content::ColorChooser* WebContentsDelegate::OpenColorChooser( - WebContents* web_contents, SkColor color) { + WebContents* web_contents, + SkColor color, + const std::vector<ColorSuggestion>& suggestions) { return NULL; } diff --git a/content/public/browser/web_contents_delegate.h b/content/public/browser/web_contents_delegate.h index 69fc22c..18bd9ef 100644 --- a/content/public/browser/web_contents_delegate.h +++ b/content/public/browser/web_contents_delegate.h @@ -39,6 +39,7 @@ class RenderViewHost; class SessionStorageNamespace; class WebContents; class WebContentsImpl; +struct ColorSuggestion; struct ContextMenuParams; struct DropData; struct FileChooserParams; @@ -333,8 +334,10 @@ class CONTENT_EXPORT WebContentsDelegate { // Called when color chooser should open. Returns the opened color chooser. // Ownership of the returned pointer is transferred to the caller. - virtual ColorChooser* OpenColorChooser(WebContents* web_contents, - SkColor color); + virtual ColorChooser* OpenColorChooser( + WebContents* web_contents, + SkColor color, + const std::vector<ColorSuggestion>& suggestions); // Called when a file selection is to be done. virtual void RunFileChooser(WebContents* web_contents, diff --git a/content/public/common/color_suggestion.cc b/content/public/common/color_suggestion.cc new file mode 100644 index 0000000..0d36538 --- /dev/null +++ b/content/public/common/color_suggestion.cc @@ -0,0 +1,16 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "content/public/common/color_suggestion.h" + +#include "third_party/WebKit/public/web/WebColorSuggestion.h" + +namespace content { + +ColorSuggestion::ColorSuggestion(const blink::WebColorSuggestion& suggestion) + : color(suggestion.color), + label(suggestion.label) { +} + +} // namespace content diff --git a/content/public/common/color_suggestion.h b/content/public/common/color_suggestion.h new file mode 100644 index 0000000..dcb1a4e --- /dev/null +++ b/content/public/common/color_suggestion.h @@ -0,0 +1,30 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CONTENT_PUBLIC_COMMON_COLOR_SUGGESTION_H_ +#define CONTENT_PUBLIC_COMMON_COLOR_SUGGESTION_H_ + +#include "base/strings/string16.h" +#include "content/common/content_export.h" +#include "third_party/skia/include/core/SkColor.h" + +namespace blink { +struct WebColorSuggestion; +} + +namespace content { + +// Container for information about datalist suggestion for the color input +// control. +struct CONTENT_EXPORT ColorSuggestion { + ColorSuggestion() {} + explicit ColorSuggestion(const blink::WebColorSuggestion& suggestion); + + SkColor color; + base::string16 label; +}; + +} // namespace content + +#endif // CONTENT_PUBLIC_COMMON_COLOR_SUGGESTION_H_ diff --git a/content/renderer/render_view_impl.cc b/content/renderer/render_view_impl.cc index 2f299ab..911953c 100644 --- a/content/renderer/render_view_impl.cc +++ b/content/renderer/render_view_impl.cc @@ -156,6 +156,7 @@ #include "third_party/WebKit/public/platform/WebVector.h" #include "third_party/WebKit/public/web/WebAXObject.h" #include "third_party/WebKit/public/web/WebColorName.h" +#include "third_party/WebKit/public/web/WebColorSuggestion.h" #include "third_party/WebKit/public/web/WebDOMEvent.h" #include "third_party/WebKit/public/web/WebDOMMessageEvent.h" #include "third_party/WebKit/public/web/WebDataSource.h" @@ -2660,10 +2661,15 @@ bool RenderViewImpl::handleCurrentKeyboardEvent() { blink::WebColorChooser* RenderViewImpl::createColorChooser( blink::WebColorChooserClient* client, - const blink::WebColor& initial_color) { + const blink::WebColor& initial_color, + const blink::WebVector<blink::WebColorSuggestion>& suggestions) { RendererWebColorChooserImpl* color_chooser = new RendererWebColorChooserImpl(this, client); - color_chooser->Open(static_cast<SkColor>(initial_color)); + std::vector<content::ColorSuggestion> color_suggestions; + for (size_t i = 0; i < suggestions.size(); i++) { + color_suggestions.push_back(content::ColorSuggestion(suggestions[i])); + } + color_chooser->Open(static_cast<SkColor>(initial_color), color_suggestions); return color_chooser; } diff --git a/content/renderer/render_view_impl.h b/content/renderer/render_view_impl.h index 5f3e891..c8f2d49 100644 --- a/content/renderer/render_view_impl.h +++ b/content/renderer/render_view_impl.h @@ -455,7 +455,9 @@ class CONTENT_EXPORT RenderViewImpl virtual void didExecuteCommand(const blink::WebString& command_name); virtual bool handleCurrentKeyboardEvent(); virtual blink::WebColorChooser* createColorChooser( - blink::WebColorChooserClient*, const blink::WebColor& initial_color); + blink::WebColorChooserClient*, + const blink::WebColor& initial_color, + const blink::WebVector<blink::WebColorSuggestion>& suggestions); virtual bool runFileChooser( const blink::WebFileChooserParams& params, blink::WebFileChooserCompletion* chooser_completion); diff --git a/content/renderer/renderer_webcolorchooser_impl.cc b/content/renderer/renderer_webcolorchooser_impl.cc index af04dab..5cfbd73 100644 --- a/content/renderer/renderer_webcolorchooser_impl.cc +++ b/content/renderer/renderer_webcolorchooser_impl.cc @@ -47,9 +47,13 @@ void RendererWebColorChooserImpl::endChooser() { Send(new ViewHostMsg_EndColorChooser(routing_id(), identifier_)); } -void RendererWebColorChooserImpl::Open(SkColor initial_color) { - Send(new ViewHostMsg_OpenColorChooser(routing_id(), identifier_, - initial_color)); +void RendererWebColorChooserImpl::Open( + SkColor initial_color, + const std::vector<content::ColorSuggestion>& suggestions) { + Send(new ViewHostMsg_OpenColorChooser(routing_id(), + identifier_, + initial_color, + suggestions)); } void RendererWebColorChooserImpl::OnDidChooseColorResponse(int color_chooser_id, diff --git a/content/renderer/renderer_webcolorchooser_impl.h b/content/renderer/renderer_webcolorchooser_impl.h index 4d6540b..d753478 100644 --- a/content/renderer/renderer_webcolorchooser_impl.h +++ b/content/renderer/renderer_webcolorchooser_impl.h @@ -5,7 +5,10 @@ #ifndef CONTENT_RENDERER_RENDERER_WEBCOLORCHOOSER_IMPL_H_ #define CONTENT_RENDERER_RENDERER_WEBCOLORCHOOSER_IMPL_H_ +#include <vector> + #include "base/compiler_specific.h" +#include "content/public/common/color_suggestion.h" #include "content/public/renderer/render_view_observer.h" #include "third_party/WebKit/public/web/WebColorChooser.h" #include "third_party/WebKit/public/web/WebColorChooserClient.h" @@ -28,7 +31,8 @@ class RendererWebColorChooserImpl : public blink::WebColorChooser, virtual void setSelectedColor(const blink::WebColor); virtual void endChooser(); - void Open(SkColor initial_color); + void Open(SkColor initial_color, + const std::vector<content::ColorSuggestion>& suggestions); blink::WebColorChooserClient* client() { return client_; } diff --git a/ui/android/java/res/drawable/color_button_background.xml b/ui/android/java/res/drawable/color_button_background.xml new file mode 100644 index 0000000..66bcce2 --- /dev/null +++ b/ui/android/java/res/drawable/color_button_background.xml @@ -0,0 +1,36 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright 2013 The Chromium Authors. All rights reserved. + Use of this source code is governed by a BSD-style license that can be + found in the LICENSE file. +--> + +<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> + <item + android:top="0dp" + android:right="0dp" + android:bottom="0dp" + android:left="0dp"> + <shape android:shape="rectangle"> + <solid android:color="@color/color_picker_border_color"/> + </shape> + </item> + <item android:top="0px" + android:right="1px" + android:bottom="0px" + android:left="1px"> + <shape android:shape="rectangle"> + <solid android:color="@color/color_picker_background_color"/> + </shape> + </item> + <item + android:id="@+id/color_button_swatch" + android:top="1px" + android:right="2px" + android:bottom="1px" + android:left="2px"> + <shape android:shape="rectangle"> + <solid android:color="#FF0000"/> + </shape> + </item> +</layer-list> diff --git a/ui/android/java/res/drawable/color_picker_border.xml b/ui/android/java/res/drawable/color_picker_border.xml index b48be9b..6cd6bbf 100644 --- a/ui/android/java/res/drawable/color_picker_border.xml +++ b/ui/android/java/res/drawable/color_picker_border.xml @@ -3,8 +3,10 @@ Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. --> + <shape xmlns:android="http://schemas.android.com/apk/res/android" - android:shape="rectangle"> - <solid android:color="#00000000"/> - <stroke android:width="1px" android:color="@color/color_picker_border_color" /> + android:shape="rectangle"> + + <stroke android:width="1px" android:color="@color/color_picker_border_color" /> + <solid android:color="@color/color_picker_background_color"/> </shape>
\ No newline at end of file diff --git a/ui/android/java/res/layout/color_picker_dialog_content.xml b/ui/android/java/res/layout/color_picker_dialog_content.xml index 8aa4dba..38a492d 100644 --- a/ui/android/java/res/layout/color_picker_dialog_content.xml +++ b/ui/android/java/res/layout/color_picker_dialog_content.xml @@ -4,53 +4,48 @@ Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. --> -<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" + +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" - android:layout_height="match_parent"> + android:layout_height="wrap_content" + android:orientation="vertical" + android:padding="15dp"> - <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" + <ScrollView android:layout_width="match_parent" - android:layout_height="match_parent" - android:orientation="vertical" - android:padding="15dp"> + android:layout_height="wrap_content"> <org.chromium.ui.ColorPickerAdvanced android:id="@+id/color_picker_advanced" android:layout_width="match_parent" android:layout_height="wrap_content" /> + </ScrollView> - <FrameLayout - android:id="@+id/color_picker_simple_border" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:background="@drawable/color_picker_border" - android:paddingStart="1px" - android:paddingEnd="1px" - android:paddingTop="1px"> + <org.chromium.ui.ColorPickerSimple + android:id="@+id/color_picker_simple" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:divider="@color/color_picker_border_color" + android:dividerHeight="1px" + android:paddingStart="1px" + android:paddingEnd="1px" + android:paddingTop="1px" + android:background="@drawable/color_picker_border" /> - <org.chromium.ui.ColorPickerSimple - android:id="@+id/color_picker_simple" - android:layout_width="match_parent" - android:layout_height="100dp"/> - </FrameLayout> + <FrameLayout + android:id="@+id/more_colors_button_border" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:background="@drawable/color_picker_border" + android:padding="1px"> - <FrameLayout - android:id="@+id/more_colors_button_border" + <org.chromium.ui.ColorPickerMoreButton + android:id="@+id/more_colors_button" + style="?android:attr/buttonBarButtonStyle" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_below="@+id/color_picker_simple_border" - android:background="@drawable/color_picker_border" - android:padding="1px"> - - <org.chromium.ui.ColorPickerMoreButton - android:id="@+id/more_colors_button" - style="?android:attr/buttonBarButtonStyle" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:minHeight="48dp" - android:textAppearance="?android:attr/textAppearanceSmall" - android:text="@string/color_picker_button_more" /> - </FrameLayout> - - </RelativeLayout> -</ScrollView>
\ No newline at end of file + android:minHeight="48dp" + android:textAppearance="?android:attr/textAppearanceSmall" + android:text="@string/color_picker_button_more" /> + </FrameLayout> +</LinearLayout> diff --git a/ui/android/java/res/values/colors.xml b/ui/android/java/res/values/colors.xml index a602826..9aa152b 100644 --- a/ui/android/java/res/values/colors.xml +++ b/ui/android/java/res/values/colors.xml @@ -6,6 +6,7 @@ --> <resources> <color name="color_picker_border_color">#B0B0B0</color> + <color name="color_picker_background_color">#FFFFFF</color> <color name="autofill_divider_color">#E5E5E5</color> <color name="autofill_dark_divider_color">#C0C0C0</color> </resources> diff --git a/ui/android/java/res/values/dimens.xml b/ui/android/java/res/values/dimens.xml index 01bc555..8bdacc7 100644 --- a/ui/android/java/res/values/dimens.xml +++ b/ui/android/java/res/values/dimens.xml @@ -11,6 +11,7 @@ of the seek bar icon. --> <dimen name="color_picker_gradient_margin">14.5dp</dimen> + <dimen name="color_button_height">60dp</dimen> <dimen name="autofill_text_height">44dp</dimen> <dimen name="autofill_text_divider_height">1px</dimen> diff --git a/ui/android/java/resource_map/org/chromium/ui/R.java b/ui/android/java/resource_map/org/chromium/ui/R.java index 8f8e499..778d99d 100644 --- a/ui/android/java/resource_map/org/chromium/ui/R.java +++ b/ui/android/java/resource_map/org/chromium/ui/R.java @@ -25,6 +25,14 @@ public final class R { public static int color_picker_button_set; public static int color_picker_button_cancel; public static int color_picker_dialog_title; + public static int color_picker_button_red; + public static int color_picker_button_cyan; + public static int color_picker_button_blue; + public static int color_picker_button_green; + public static int color_picker_button_magenta; + public static int color_picker_button_yellow; + public static int color_picker_button_black; + public static int color_picker_button_white; } public static final class id { public static int autofill_label; @@ -35,6 +43,7 @@ public final class R { public static int more_colors_button; public static int color_picker_advanced; public static int color_picker_simple; + public static int color_button_swatch; public static int more_colors_button_border; public static int color_picker_simple_border; public static int gradient; @@ -48,6 +57,7 @@ public final class R { public static int color_picker_advanced_component; } public static final class drawable { + public static int color_button_background; public static int color_picker_advanced_select_handle; } public static final class style { @@ -61,5 +71,6 @@ public final class R { public static final class dimen { public static int autofill_text_height; public static int autofill_text_divider_height; + public static int color_button_height; } } diff --git a/ui/android/java/src/org/chromium/ui/ColorPickerAdvanced.java b/ui/android/java/src/org/chromium/ui/ColorPickerAdvanced.java index 91800ea..f75e487 100644 --- a/ui/android/java/src/org/chromium/ui/ColorPickerAdvanced.java +++ b/ui/android/java/src/org/chromium/ui/ColorPickerAdvanced.java @@ -70,7 +70,6 @@ public class ColorPickerAdvanced extends LinearLayout implements OnSeekBarChange SATURATION_SEEK_BAR_MAX, this); mValueDetails = createAndAddNewGradient(R.string.color_picker_value, VALUE_SEEK_BAR_MAX, this); - refreshGradientComponents(); } diff --git a/ui/android/java/src/org/chromium/ui/ColorPickerDialog.java b/ui/android/java/src/org/chromium/ui/ColorPickerDialog.java index 58f1e0a..ca4d245 100644 --- a/ui/android/java/src/org/chromium/ui/ColorPickerDialog.java +++ b/ui/android/java/src/org/chromium/ui/ColorPickerDialog.java @@ -38,8 +38,12 @@ public class ColorPickerDialog extends AlertDialog implements OnColorChangedList * @param theme The theme to display the dialog in. * @param listener The object to notify when the color is set. * @param color The initial color to set. + * @param suggestions The list of suggestions. */ - public ColorPickerDialog(Context context, OnColorChangedListener listener, int color) { + public ColorPickerDialog(Context context, + OnColorChangedListener listener, + int color, + ColorSuggestion[] suggestions) { super(context, 0); mListener = listener; @@ -110,7 +114,7 @@ public class ColorPickerDialog extends AlertDialog implements OnColorChangedList // Initialize simple color view (default view). mSimpleColorPicker = (ColorPickerSimple) content.findViewById(R.id.color_picker_simple); - mSimpleColorPicker.init(this); + mSimpleColorPicker.init(suggestions, this); updateCurrentColor(mInitialColor); } @@ -136,8 +140,8 @@ public class ColorPickerDialog extends AlertDialog implements OnColorChangedList View buttonBorder = findViewById(R.id.more_colors_button_border); buttonBorder.setVisibility(View.GONE); - View simpleViewBorder = findViewById(R.id.color_picker_simple_border); - simpleViewBorder.setVisibility(View.GONE); + View simpleView = findViewById(R.id.color_picker_simple); + simpleView.setVisibility(View.GONE); mAdvancedColorPicker.setVisibility(View.VISIBLE); mAdvancedColorPicker.setListener(this); diff --git a/ui/android/java/src/org/chromium/ui/ColorPickerSimple.java b/ui/android/java/src/org/chromium/ui/ColorPickerSimple.java index 979405a..1644ba8 100644 --- a/ui/android/java/src/org/chromium/ui/ColorPickerSimple.java +++ b/ui/android/java/src/org/chromium/ui/ColorPickerSimple.java @@ -11,40 +11,42 @@ import android.graphics.Rect; import android.util.AttributeSet; import android.view.MotionEvent; import android.view.View; +import android.view.ViewGroup; +import android.widget.ListView; +import android.widget.AdapterView; +import org.chromium.ui.ColorSuggestionListAdapter.OnColorSuggestionClickListener; + +import java.util.ArrayList; +import java.util.Arrays; /** * Draws a grid of (predefined) colors and allows the user to choose one of * those colors. */ -public class ColorPickerSimple extends View { - private static final int ROW_COUNT = 2; - - private static final int COLUMN_COUNT = 4; - - private static final int GRID_CELL_COUNT = ROW_COUNT * COLUMN_COUNT; - - private static final int[] COLORS = { Color.RED, - Color.CYAN, - Color.BLUE, - Color.GREEN, - Color.MAGENTA, - Color.YELLOW, - Color.BLACK, - Color.WHITE - }; - - private Paint mBorderPaint; - - private Rect[] mBounds; - - private Paint[] mPaints; - - private OnColorChangedListener mOnColorTouchedListener; - - private int mLastTouchedXPosition; - - private int mLastTouchedYPosition; +public class ColorPickerSimple extends ListView implements OnColorSuggestionClickListener { + + private OnColorChangedListener mOnColorChangedListener; + + private static final int[] DEFAULT_COLORS = { Color.RED, + Color.CYAN, + Color.BLUE, + Color.GREEN, + Color.MAGENTA, + Color.YELLOW, + Color.BLACK, + Color.WHITE + }; + + private static final int[] DEFAULT_COLOR_LABEL_IDS = { R.string.color_picker_button_red, + R.string.color_picker_button_cyan, + R.string.color_picker_button_blue, + R.string.color_picker_button_green, + R.string.color_picker_button_magenta, + R.string.color_picker_button_yellow, + R.string.color_picker_button_black, + R.string.color_picker_button_white + }; public ColorPickerSimple(Context context) { super(context); @@ -59,131 +61,35 @@ public class ColorPickerSimple extends View { } /** - * Initializes the listener and precalculates the grid and color positions. + * Initializes the listener and sets the adapter for the given list of suggestions. If the + * suggestions is null a default set of colors will be used. * + * @param suggestions The list of suggestions that should be displayed. * @param onColorChangedListener The listener that gets notified when the user touches * a color. */ - public void init(OnColorChangedListener onColorChangedListener) { - mOnColorTouchedListener = onColorChangedListener; - - // This will get calculated when the layout size is updated. - mBounds = null; - - mPaints = new Paint[GRID_CELL_COUNT]; - for (int i = 0; i < GRID_CELL_COUNT; ++i) { - Paint newPaint = new Paint(); - newPaint.setColor(COLORS[i]); - mPaints[i] = newPaint; - } - - mBorderPaint = new Paint(); - int borderColor = getContext().getResources().getColor(R.color.color_picker_border_color); - mBorderPaint.setColor(borderColor); - - // Responds to the user touching the grid and works out which color has been chosen as - // a result, depending on the X,Y coordinate. Note that we respond to the click event - // here, but the onClick() method doesn't provide us with the X,Y coordinates, so we - // track them in onTouchEvent() below. This way the grid reacts properly to touch events - // whereas if we put this onClick() code in onTouchEvent below then we get some strange - // interactions with the ScrollView in the parent ColorPickerDialog. - setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - if (mOnColorTouchedListener != null && getWidth() > 0 && getHeight() > 0) { - int column = mLastTouchedXPosition * COLUMN_COUNT / getWidth(); - int row = mLastTouchedYPosition * ROW_COUNT / getHeight(); - - int colorIndex = (row * COLUMN_COUNT) + column; - if (colorIndex >= 0 && colorIndex < COLORS.length) { - mOnColorTouchedListener.onColorChanged(COLORS[colorIndex]); - } - } + public void init(ColorSuggestion[] suggestions, + OnColorChangedListener onColorChangedListener) { + mOnColorChangedListener = onColorChangedListener; + + if (suggestions == null) { + suggestions = new ColorSuggestion[DEFAULT_COLORS.length]; + for (int i = 0; i < suggestions.length; ++i) { + suggestions[i] = + new ColorSuggestion( + DEFAULT_COLORS[i], + getContext().getString(DEFAULT_COLOR_LABEL_IDS[i])); } - }); - } - - /** - * Draws the grid of colors, based on the rectangles calculated in onSizeChanged(). - * Also draws borders in between the colored rectangles. - * - * @param canvas The canvas the colors are drawn onto. - */ - @Override - public void onDraw(Canvas canvas) { - if (mBounds == null || mPaints == null) { - return; - } - - canvas.drawColor(Color.WHITE); - - // Draw the actual colored rectangles. - for (int i = 0; i < GRID_CELL_COUNT; ++i) { - canvas.drawRect(mBounds[i], mPaints[i]); - } - - // Draw 1px borders between the rows. - for (int i = 0; i < ROW_COUNT - 1; ++i) { - canvas.drawLine(0, - mBounds[i * COLUMN_COUNT].bottom + 1, - getWidth(), - mBounds[i * COLUMN_COUNT].bottom + 1, - mBorderPaint); } - // Draw 1px borders between the columns. - for (int j = 0; j < COLUMN_COUNT - 1; ++j) { - canvas.drawLine(mBounds[j].right + 1, - 0, - mBounds[j].right + 1, - getHeight(), - mBorderPaint); - } + ColorSuggestionListAdapter adapter = new ColorSuggestionListAdapter(getContext(), + suggestions); + adapter.setOnColorSuggestionClickListener(this); + setAdapter(adapter); } - /** - * Stores the X,Y coordinates of the touch so that we can use them in the onClick() listener - * above to work out where the click was on the grid. - * - * @param event The MotionEvent the X,Y coordinates are retrieved from. - */ @Override - public boolean onTouchEvent(MotionEvent event) { - if (event.getAction() == MotionEvent.ACTION_DOWN) { - mLastTouchedXPosition = (int) event.getX(); - mLastTouchedYPosition = (int) event.getY(); - } - return super.onTouchEvent(event); - } - - /** - * Recalculates the color grid with the new sizes. - */ - @Override - protected void onSizeChanged(int width, int height, int oldw, int oldh) { - calculateGrid(width, height); - } - - /** - * Calculates the sizes and positions of the cells in the grid, splitting - * them up as evenly as possible. Leaves 3 pixels between each cell so that - * we can draw a border between them as well, and leaves a pixel around the - * edge. - */ - private void calculateGrid(final int width, final int height) { - mBounds = new Rect[GRID_CELL_COUNT]; - - for (int i = 0; i < ROW_COUNT; ++i) { - for (int j = 0; j < COLUMN_COUNT; ++j) { - int left = j * (width + 1) / COLUMN_COUNT + 1; - int right = (j + 1) * (width + 1) / COLUMN_COUNT - 2; - - int top = i * (height + 1) / ROW_COUNT + 1; - int bottom = (i + 1) * (height + 1) / ROW_COUNT - 2; - - Rect rect = new Rect(left, top, right, bottom); - mBounds[(i * COLUMN_COUNT) + j] = rect; - } - } + public void onColorSuggestionClick(ColorSuggestion suggestion) { + mOnColorChangedListener.onColorChanged(suggestion.mColor); } } diff --git a/ui/android/java/src/org/chromium/ui/ColorSuggestion.java b/ui/android/java/src/org/chromium/ui/ColorSuggestion.java new file mode 100644 index 0000000..4e964a7 --- /dev/null +++ b/ui/android/java/src/org/chromium/ui/ColorSuggestion.java @@ -0,0 +1,24 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package org.chromium.ui; + +/** + * Color suggestion container used to store information for each color button that will be shown in + * the simple color picker. + */ +public class ColorSuggestion { + final int mColor; + final String mLabel; + + /** + * Constructs a color suggestion container. + * @param color The suggested color. + * @param label The label for the suggestion. + */ + public ColorSuggestion(int color, String label) { + mColor = color; + mLabel = label; + } +} diff --git a/ui/android/java/src/org/chromium/ui/ColorSuggestionListAdapter.java b/ui/android/java/src/org/chromium/ui/ColorSuggestionListAdapter.java new file mode 100644 index 0000000..04bccea --- /dev/null +++ b/ui/android/java/src/org/chromium/ui/ColorSuggestionListAdapter.java @@ -0,0 +1,146 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package org.chromium.ui; + +import android.content.Context; +import android.graphics.Color; +import android.graphics.drawable.GradientDrawable; +import android.graphics.drawable.LayerDrawable; +import android.text.TextUtils; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.AbsListView; +import android.widget.BaseAdapter; +import android.widget.GridView; +import android.widget.LinearLayout; + +import org.chromium.base.ApiCompatibilityUtils; + +import java.util.ArrayList; + +/** + * The adapter used to populate ColorPickerSimple. + */ +public class ColorSuggestionListAdapter extends BaseAdapter implements View.OnClickListener { + private Context mContext; + private ColorSuggestion[] mSuggestions; + private OnColorSuggestionClickListener mListener; + + /** + * The callback used to indicate the user has clicked on a suggestion. + */ + public interface OnColorSuggestionClickListener { + + /** + * Called upon a click on a suggestion. + * + * @param suggestion The suggestion that was clicked. + */ + void onColorSuggestionClick(ColorSuggestion suggestion); + } + + private final static int COLORS_PER_ROW = 4; + + ColorSuggestionListAdapter(Context context, ColorSuggestion[] suggestions) { + mContext = context; + mSuggestions = suggestions; + } + + /** + * Sets the listener that will be notified upon a click on a suggestion. + */ + public void setOnColorSuggestionClickListener(OnColorSuggestionClickListener listener) { + mListener = listener; + } + + /** + * Sets up the color button to represent a color suggestion. + * + * @param button The button view to set up. + * @param index The index of the suggestion in mSuggestions. + */ + private void setUpColorButton(View button, int index) { + if (index >= mSuggestions.length) { + button.setTag(null); + button.setContentDescription(null); + button.setVisibility(View.INVISIBLE); + return; + } + button.setTag(mSuggestions[index]); + button.setVisibility(View.VISIBLE); + ColorSuggestion suggestion = mSuggestions[index]; + LayerDrawable layers = (LayerDrawable) button.getBackground(); + GradientDrawable swatch = + (GradientDrawable) layers.findDrawableByLayerId(R.id.color_button_swatch); + swatch.setColor(suggestion.mColor); + String description = suggestion.mLabel; + if (TextUtils.isEmpty(description)) { + description = String.format("#%06X", (0xFFFFFF & suggestion.mColor)); + } + button.setContentDescription(description); + button.setOnClickListener(this); + } + + @Override + public void onClick(View v) { + if (mListener == null) { + return; + } + ColorSuggestion suggestion = (ColorSuggestion) v.getTag(); + if (suggestion == null) { + return; + } + mListener.onColorSuggestionClick(suggestion); + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + LinearLayout layout; + if (convertView != null && convertView instanceof LinearLayout) { + layout = (LinearLayout) convertView; + } else { + layout = new LinearLayout(mContext); + layout.setLayoutParams(new AbsListView.LayoutParams( + AbsListView.LayoutParams.MATCH_PARENT, + AbsListView.LayoutParams.WRAP_CONTENT)); + layout.setOrientation(LinearLayout.HORIZONTAL); + layout.setBackgroundColor(Color.WHITE); + int buttonHeight = + mContext.getResources().getDimensionPixelOffset(R.dimen.color_button_height); + for (int i = 0; i < COLORS_PER_ROW; ++i) { + View button = new View(mContext); + LinearLayout.LayoutParams layoutParams = + new LinearLayout.LayoutParams(0, buttonHeight, 1f); + ApiCompatibilityUtils.setMarginStart(layoutParams, -1); + if (i == COLORS_PER_ROW - 1) { + ApiCompatibilityUtils.setMarginEnd(layoutParams, -1); + } + button.setLayoutParams(layoutParams); + button.setBackgroundResource(R.drawable.color_button_background); + layout.addView(button); + } + } + for (int i = 0; i < COLORS_PER_ROW; ++i) { + setUpColorButton(layout.getChildAt(i), position * COLORS_PER_ROW + i); + } + return layout; + } + + @Override + public long getItemId(int position) { + return position; + } + + @Override + public Object getItem(int position) { + return null; + } + + @Override + public int getCount() { + return (mSuggestions.length + COLORS_PER_ROW - 1) / COLORS_PER_ROW; + } +} diff --git a/ui/android/java/strings/android_ui_strings.grd b/ui/android/java/strings/android_ui_strings.grd index ee2f2d4..b4a03a8 100644 --- a/ui/android/java/strings/android_ui_strings.grd +++ b/ui/android/java/strings/android_ui_strings.grd @@ -29,6 +29,30 @@ <message desc="Title of ColorPicker dialog. [CHAR-LIMIT=20]" name="IDS_COLOR_PICKER_DIALOG_TITLE"> Select color </message> + <message desc="Accessibility label for button to select the red color." name="IDS_COLOR_PICKER_BUTTON_RED"> + Red + </message> + <message desc="Accessibility label for button to select the cyan color." name="IDS_COLOR_PICKER_BUTTON_CYAN"> + Cyan + </message> + <message desc="Accessibility label for button to select the blue color." name="IDS_COLOR_PICKER_BUTTON_BLUE"> + Blue + </message> + <message desc="Accessibility label for button to select the green color." name="IDS_COLOR_PICKER_BUTTON_GREEN"> + Green + </message> + <message desc="Accessibility label for button to select the magenta color." name="IDS_COLOR_PICKER_BUTTON_MAGENTA"> + Magenta + </message> + <message desc="Accessibility label for button to select the yellow color." name="IDS_COLOR_PICKER_BUTTON_YELLOW"> + Yellow + </message> + <message desc="Accessibility label for button to select the black color." name="IDS_COLOR_PICKER_BUTTON_BLACK"> + Black + </message> + <message desc="Accessibility label for button to select the white color." name="IDS_COLOR_PICKER_BUTTON_WHITE"> + White + </message> </messages> </release> <translations> |