- add sources.
[platform/framework/web/crosswalk.git] / src / components / web_contents_delegate_android / color_chooser_android.cc
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.
4
5 #include "components/web_contents_delegate_android/color_chooser_android.h"
6
7 #include "content/public/browser/android/content_view_core.h"
8 #include "content/public/browser/web_contents.h"
9 #include "content/public/browser/web_contents_view.h"
10 #include "jni/ColorChooserAndroid_jni.h"
11
12 namespace web_contents_delegate_android {
13
14 ColorChooserAndroid::ColorChooserAndroid(content::WebContents* web_contents,
15                                          SkColor initial_color)
16     : web_contents_(web_contents) {
17   JNIEnv* env = AttachCurrentThread();
18   content::ContentViewCore* content_view_core =
19       content::ContentViewCore::FromWebContents(web_contents);
20   DCHECK(content_view_core);
21
22   j_color_chooser_.Reset(Java_ColorChooserAndroid_createColorChooserAndroid(
23       env,
24       reinterpret_cast<intptr_t>(this),
25       content_view_core->GetJavaObject().obj(),
26       initial_color));
27 }
28
29 ColorChooserAndroid::~ColorChooserAndroid() {
30 }
31
32 void ColorChooserAndroid::End() {
33   if (!j_color_chooser_.is_null()) {
34     JNIEnv* env = AttachCurrentThread();
35     Java_ColorChooserAndroid_closeColorChooser(env, j_color_chooser_.obj());
36   }
37 }
38
39 void ColorChooserAndroid::SetSelectedColor(SkColor color) {
40   // Not implemented since the color is set on the java side only, in theory
41   // it can be set from JS which would override the user selection but
42   // we don't support that for now.
43 }
44
45 void ColorChooserAndroid::OnColorChosen(JNIEnv* env, jobject obj, jint color) {
46   web_contents_->DidChooseColorInColorChooser(color);
47   web_contents_->DidEndColorChooser();
48 }
49
50 // ----------------------------------------------------------------------------
51 // Native JNI methods
52 // ----------------------------------------------------------------------------
53 bool RegisterColorChooserAndroid(JNIEnv* env) {
54   return RegisterNativesImpl(env);
55 }
56
57 }  // namespace web_contents_delegate_android