OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/web_contents_delegate_android/color_chooser_android.h" | 5 #include "components/web_contents_delegate_android/color_chooser_android.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/android/jni_array.h" | 9 #include "base/android/jni_array.h" |
10 #include "base/android/jni_string.h" | 10 #include "base/android/jni_string.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 | 30 |
31 if (suggestions.size() > 0) { | 31 if (suggestions.size() > 0) { |
32 suggestions_array = Java_ColorChooserAndroid_createColorSuggestionArray( | 32 suggestions_array = Java_ColorChooserAndroid_createColorSuggestionArray( |
33 env, suggestions.size()); | 33 env, suggestions.size()); |
34 | 34 |
35 for (size_t i = 0; i < suggestions.size(); ++i) { | 35 for (size_t i = 0; i < suggestions.size(); ++i) { |
36 const content::ColorSuggestion& suggestion = suggestions[i]; | 36 const content::ColorSuggestion& suggestion = suggestions[i]; |
37 ScopedJavaLocalRef<jstring> label = ConvertUTF16ToJavaString( | 37 ScopedJavaLocalRef<jstring> label = ConvertUTF16ToJavaString( |
38 env, suggestion.label); | 38 env, suggestion.label); |
39 Java_ColorChooserAndroid_addToColorSuggestionArray( | 39 Java_ColorChooserAndroid_addToColorSuggestionArray( |
40 env, | 40 env, suggestions_array, i, suggestion.color, label); |
41 suggestions_array.obj(), | |
42 i, | |
43 suggestion.color, | |
44 label.obj()); | |
45 } | 41 } |
46 } | 42 } |
47 | 43 |
48 ContentViewCore* content_view_core = | 44 ContentViewCore* content_view_core = |
49 ContentViewCore::FromWebContents(web_contents); | 45 ContentViewCore::FromWebContents(web_contents); |
50 if (content_view_core) { | 46 if (content_view_core) { |
51 base::android::ScopedJavaLocalRef<jobject> java_content_view_core = | 47 base::android::ScopedJavaLocalRef<jobject> java_content_view_core = |
52 content_view_core->GetJavaObject(); | 48 content_view_core->GetJavaObject(); |
53 if (!java_content_view_core.is_null()) { | 49 if (!java_content_view_core.is_null()) { |
54 j_color_chooser_.Reset(Java_ColorChooserAndroid_createColorChooserAndroid( | 50 j_color_chooser_.Reset(Java_ColorChooserAndroid_createColorChooserAndroid( |
55 env, | 51 env, reinterpret_cast<intptr_t>(this), java_content_view_core, |
56 reinterpret_cast<intptr_t>(this), | 52 initial_color, suggestions_array)); |
57 java_content_view_core.obj(), | |
58 initial_color, | |
59 suggestions_array.obj())); | |
60 } | 53 } |
61 } | 54 } |
62 if (j_color_chooser_.is_null()) | 55 if (j_color_chooser_.is_null()) |
63 OnColorChosen(env, j_color_chooser_, initial_color); | 56 OnColorChosen(env, j_color_chooser_, initial_color); |
64 } | 57 } |
65 | 58 |
66 ColorChooserAndroid::~ColorChooserAndroid() { | 59 ColorChooserAndroid::~ColorChooserAndroid() { |
67 } | 60 } |
68 | 61 |
69 void ColorChooserAndroid::End() { | 62 void ColorChooserAndroid::End() { |
70 if (!j_color_chooser_.is_null()) { | 63 if (!j_color_chooser_.is_null()) { |
71 JNIEnv* env = AttachCurrentThread(); | 64 JNIEnv* env = AttachCurrentThread(); |
72 Java_ColorChooserAndroid_closeColorChooser(env, j_color_chooser_.obj()); | 65 Java_ColorChooserAndroid_closeColorChooser(env, j_color_chooser_); |
73 } | 66 } |
74 } | 67 } |
75 | 68 |
76 void ColorChooserAndroid::SetSelectedColor(SkColor color) { | 69 void ColorChooserAndroid::SetSelectedColor(SkColor color) { |
77 // Not implemented since the color is set on the java side only, in theory | 70 // Not implemented since the color is set on the java side only, in theory |
78 // it can be set from JS which would override the user selection but | 71 // it can be set from JS which would override the user selection but |
79 // we don't support that for now. | 72 // we don't support that for now. |
80 } | 73 } |
81 | 74 |
82 void ColorChooserAndroid::OnColorChosen(JNIEnv* env, | 75 void ColorChooserAndroid::OnColorChosen(JNIEnv* env, |
83 const JavaRef<jobject>& obj, | 76 const JavaRef<jobject>& obj, |
84 jint color) { | 77 jint color) { |
85 web_contents_->DidChooseColorInColorChooser(color); | 78 web_contents_->DidChooseColorInColorChooser(color); |
86 web_contents_->DidEndColorChooser(); | 79 web_contents_->DidEndColorChooser(); |
87 } | 80 } |
88 | 81 |
89 // ---------------------------------------------------------------------------- | 82 // ---------------------------------------------------------------------------- |
90 // Native JNI methods | 83 // Native JNI methods |
91 // ---------------------------------------------------------------------------- | 84 // ---------------------------------------------------------------------------- |
92 bool RegisterColorChooserAndroid(JNIEnv* env) { | 85 bool RegisterColorChooserAndroid(JNIEnv* env) { |
93 return RegisterNativesImpl(env); | 86 return RegisterNativesImpl(env); |
94 } | 87 } |
95 | 88 |
96 } // namespace web_contents_delegate_android | 89 } // namespace web_contents_delegate_android |
OLD | NEW |