Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / components / web_contents_delegate_android / validation_message_bubble_android.cc
blob8ea3af0b05e8b1e7f4d72458f3e221604b3e5ba7
1 // Copyright (c) 2013 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 "components/web_contents_delegate_android/validation_message_bubble_android.h"
7 #include "base/android/jni_string.h"
8 #include "content/public/browser/android/content_view_core.h"
9 #include "content/public/browser/render_view_host.h"
10 #include "content/public/browser/web_contents.h"
11 #include "jni/ValidationMessageBubble_jni.h"
12 #include "ui/gfx/rect.h"
14 using base::android::ConvertUTF16ToJavaString;
15 using content::ContentViewCore;
16 using content::RenderWidgetHost;
18 namespace {
20 inline ContentViewCore* GetContentViewCoreFrom(RenderWidgetHost* widget_host) {
21 return ContentViewCore::FromWebContents(
22 content::WebContents::FromRenderViewHost(
23 content::RenderViewHost::From(widget_host)));
28 namespace web_contents_delegate_android {
30 ValidationMessageBubbleAndroid::ValidationMessageBubbleAndroid(
31 RenderWidgetHost* widget_host,
32 const gfx::Rect& anchor_in_root_view,
33 const base::string16& main_text,
34 const base::string16& sub_text) {
35 JNIEnv* env = base::android::AttachCurrentThread();
36 java_validation_message_bubble_.Reset(
37 Java_ValidationMessageBubble_createAndShow(
38 env,
39 GetContentViewCoreFrom(widget_host)->GetJavaObject().obj(),
40 anchor_in_root_view.x(),
41 anchor_in_root_view.y(),
42 anchor_in_root_view.width(),
43 anchor_in_root_view.height(),
44 ConvertUTF16ToJavaString(env, main_text).obj(),
45 ConvertUTF16ToJavaString(env, sub_text).obj()));
48 ValidationMessageBubbleAndroid::~ValidationMessageBubbleAndroid() {
49 Java_ValidationMessageBubble_close(base::android::AttachCurrentThread(),
50 java_validation_message_bubble_.obj());
53 void ValidationMessageBubbleAndroid::SetPositionRelativeToAnchor(
54 RenderWidgetHost* widget_host, const gfx::Rect& anchor_in_root_view) {
55 Java_ValidationMessageBubble_setPositionRelativeToAnchor(
56 base::android::AttachCurrentThread(),
57 java_validation_message_bubble_.obj(),
58 GetContentViewCoreFrom(widget_host)->GetJavaObject().obj(),
59 anchor_in_root_view.x(),
60 anchor_in_root_view.y(),
61 anchor_in_root_view.width(),
62 anchor_in_root_view.height());
65 // static
66 bool ValidationMessageBubbleAndroid::Register(JNIEnv* env) {
67 return RegisterNativesImpl(env);
70 } // namespace web_contents_delegate_android