| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 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 "chrome/browser/ui/android/validation_message_bubble_android.h" | 5 #include "chrome/browser/ui/android/validation_message_bubble_android.h" |
| 6 | 6 |
| 7 #include "base/android/jni_string.h" | 7 #include "base/android/jni_string.h" |
| 8 #include "content/public/browser/android/content_view_core.h" | 8 #include "content/public/browser/android/content_view_core.h" |
| 9 #include "content/public/browser/render_view_host.h" | 9 #include "content/public/browser/render_view_host.h" |
| 10 #include "content/public/browser/web_contents.h" | 10 #include "content/public/browser/web_contents.h" |
| 11 #include "jni/ValidationMessageBubble_jni.h" | 11 #include "jni/ValidationMessageBubble_jni.h" |
| 12 #include "ui/gfx/rect.h" | 12 #include "ui/gfx/rect.h" |
| 13 | 13 |
| 14 using base::android::ConvertUTF16ToJavaString; | 14 using base::android::ConvertUTF16ToJavaString; |
| 15 using content::ContentViewCore; | 15 using content::ContentViewCore; |
| 16 using content::RenderWidgetHost; | 16 using content::RenderWidgetHost; |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 inline ContentViewCore* GetContentViewCoreFrom(RenderWidgetHost* widget_host) { | 20 inline ContentViewCore* GetContentViewCoreFrom(RenderWidgetHost* widget_host) { |
| 21 return ContentViewCore::FromWebContents( | 21 return ContentViewCore::FromWebContents( |
| 22 content::WebContents::FromRenderViewHost( | 22 content::WebContents::FromRenderViewHost( |
| 23 content::RenderViewHost::From(widget_host))); | 23 content::RenderViewHost::From(widget_host))); |
| 24 } | 24 } |
| 25 | 25 |
| 26 } | 26 } |
| 27 | 27 |
| 28 ValidationMessageBubbleAndroid::ValidationMessageBubbleAndroid( | 28 ValidationMessageBubbleAndroid::ValidationMessageBubbleAndroid( |
| 29 RenderWidgetHost* widget_host, | 29 RenderWidgetHost* widget_host, |
| 30 const gfx::Rect& anchor_in_screen, | 30 const gfx::Rect& anchor_in_root_view, |
| 31 const string16& main_text, | 31 const string16& main_text, |
| 32 const string16& sub_text) { | 32 const string16& sub_text) { |
| 33 JNIEnv* env = base::android::AttachCurrentThread(); | 33 JNIEnv* env = base::android::AttachCurrentThread(); |
| 34 java_validation_message_bubble_.Reset( | 34 java_validation_message_bubble_.Reset( |
| 35 Java_ValidationMessageBubble_createAndShow( | 35 Java_ValidationMessageBubble_createAndShow( |
| 36 env, | 36 env, |
| 37 GetContentViewCoreFrom(widget_host)->GetJavaObject().obj(), | 37 GetContentViewCoreFrom(widget_host)->GetJavaObject().obj(), |
| 38 anchor_in_screen.x(), | 38 anchor_in_root_view.x(), |
| 39 anchor_in_screen.y(), | 39 anchor_in_root_view.y(), |
| 40 anchor_in_screen.width(), | 40 anchor_in_root_view.width(), |
| 41 anchor_in_screen.height(), | 41 anchor_in_root_view.height(), |
| 42 ConvertUTF16ToJavaString(env, main_text).obj(), | 42 ConvertUTF16ToJavaString(env, main_text).obj(), |
| 43 ConvertUTF16ToJavaString(env, sub_text).obj())); | 43 ConvertUTF16ToJavaString(env, sub_text).obj())); |
| 44 } | 44 } |
| 45 | 45 |
| 46 ValidationMessageBubbleAndroid::~ValidationMessageBubbleAndroid() { | 46 ValidationMessageBubbleAndroid::~ValidationMessageBubbleAndroid() { |
| 47 Java_ValidationMessageBubble_close(base::android::AttachCurrentThread(), | 47 Java_ValidationMessageBubble_close(base::android::AttachCurrentThread(), |
| 48 java_validation_message_bubble_.obj()); | 48 java_validation_message_bubble_.obj()); |
| 49 } | 49 } |
| 50 | 50 |
| 51 void ValidationMessageBubbleAndroid::MoveOnAnchor( | 51 void ValidationMessageBubbleAndroid::SetPositionRelativeToAnchor( |
| 52 RenderWidgetHost* widget_host, const gfx::Rect& anchor_in_screen) { | 52 RenderWidgetHost* widget_host, const gfx::Rect& anchor_in_root_view) { |
| 53 Java_ValidationMessageBubble_moveOnAnchor( | 53 Java_ValidationMessageBubble_moveOnAnchor( |
| 54 base::android::AttachCurrentThread(), | 54 base::android::AttachCurrentThread(), |
| 55 java_validation_message_bubble_.obj(), | 55 java_validation_message_bubble_.obj(), |
| 56 GetContentViewCoreFrom(widget_host)->GetJavaObject().obj(), | 56 GetContentViewCoreFrom(widget_host)->GetJavaObject().obj(), |
| 57 anchor_in_screen.x(), | 57 anchor_in_root_view.x(), |
| 58 anchor_in_screen.y(), | 58 anchor_in_root_view.y(), |
| 59 anchor_in_screen.width(), | 59 anchor_in_root_view.width(), |
| 60 anchor_in_screen.height()); | 60 anchor_in_root_view.height()); |
| 61 } | 61 } |
| 62 | 62 |
| 63 // static | 63 // static |
| 64 bool ValidationMessageBubbleAndroid::Register(JNIEnv* env) { | 64 bool ValidationMessageBubbleAndroid::Register(JNIEnv* env) { |
| 65 return RegisterNativesImpl(env); | 65 return RegisterNativesImpl(env); |
| 66 } | 66 } |
| 67 | 67 |
| 68 namespace chrome { | 68 namespace chrome { |
| 69 | 69 |
| 70 scoped_ptr<ValidationMessageBubble> ValidationMessageBubble::CreateAndShow( | 70 scoped_ptr<ValidationMessageBubble> ValidationMessageBubble::CreateAndShow( |
| 71 RenderWidgetHost* widget_host, | 71 RenderWidgetHost* widget_host, |
| 72 const gfx::Rect& anchor_in_screen, | 72 const gfx::Rect& anchor_in_root_view, |
| 73 const string16& main_text, | 73 const string16& main_text, |
| 74 const string16& sub_text) { | 74 const string16& sub_text) { |
| 75 return scoped_ptr<ValidationMessageBubble>(new ValidationMessageBubbleAndroid( | 75 return scoped_ptr<ValidationMessageBubble>(new ValidationMessageBubbleAndroid( |
| 76 widget_host, anchor_in_screen, main_text, sub_text)).Pass(); | 76 widget_host, anchor_in_root_view, main_text, sub_text)).Pass(); |
| 77 } | 77 } |
| 78 | 78 |
| 79 } | 79 } // namespace chrome |
| OLD | NEW |