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 "components/web_contents_delegate_android/validation_message_bubble_and
roid.h" | 5 #include "components/web_contents_delegate_android/validation_message_bubble_and
roid.h" |
6 | 6 |
7 #include "base/android/jni_string.h" | 7 #include "base/android/jni_string.h" |
8 #include "jni/ValidationMessageBubble_jni.h" | 8 #include "jni/ValidationMessageBubble_jni.h" |
9 #include "ui/android/view_android.h" | 9 #include "ui/android/view_android.h" |
10 #include "ui/gfx/geometry/rect_conversions.h" | 10 #include "ui/gfx/geometry/rect_conversions.h" |
11 #include "ui/gfx/geometry/rect_f.h" | 11 #include "ui/gfx/geometry/rect_f.h" |
12 #include "ui/gfx/geometry/size_conversions.h" | 12 #include "ui/gfx/geometry/size_conversions.h" |
13 | 13 |
14 using base::android::ConvertUTF16ToJavaString; | 14 using base::android::ConvertUTF16ToJavaString; |
15 | 15 |
16 namespace { | 16 namespace { |
17 | |
18 gfx::Rect ScaleToRoundedRect(const gfx::Rect& rect, float scale) { | |
19 gfx::RectF scaledRect(rect); | |
20 scaledRect.Scale(scale); | |
21 return ToNearestRect(scaledRect); | |
22 } | |
23 | |
24 gfx::Size ScaleToRoundedSize(const gfx::SizeF& size, float scale) { | 17 gfx::Size ScaleToRoundedSize(const gfx::SizeF& size, float scale) { |
25 return gfx::ToRoundedSize(gfx::ScaleSize(size, scale)); | 18 return gfx::ToRoundedSize(gfx::ScaleSize(size, scale)); |
26 } | 19 } |
27 } // namespace | 20 } // namespace |
28 | 21 |
29 namespace web_contents_delegate_android { | 22 namespace web_contents_delegate_android { |
30 | 23 |
31 ValidationMessageBubbleAndroid::ValidationMessageBubbleAndroid( | 24 ValidationMessageBubbleAndroid::ValidationMessageBubbleAndroid( |
32 gfx::NativeView view, | 25 gfx::NativeView view, |
33 const base::string16& main_text, | 26 const base::string16& main_text, |
(...skipping 14 matching lines...) Expand all Loading... |
48 } | 41 } |
49 | 42 |
50 void ValidationMessageBubbleAndroid::ShowAtPositionRelativeToAnchor( | 43 void ValidationMessageBubbleAndroid::ShowAtPositionRelativeToAnchor( |
51 gfx::NativeView view, | 44 gfx::NativeView view, |
52 const gfx::Rect& anchor_in_screen) { | 45 const gfx::Rect& anchor_in_screen) { |
53 if (java_validation_message_bubble_.is_null()) | 46 if (java_validation_message_bubble_.is_null()) |
54 return; | 47 return; |
55 | 48 |
56 // Convert to physical unit before passing to Java. | 49 // Convert to physical unit before passing to Java. |
57 float scale = view->GetDipScale() * view->page_scale(); | 50 float scale = view->GetDipScale() * view->page_scale(); |
58 gfx::Rect anchor = ScaleToRoundedRect(anchor_in_screen, scale); | 51 gfx::RectF anchor_f = gfx::RectF(anchor_in_screen); |
| 52 anchor_f.Scale(scale); |
| 53 gfx::Rect anchor = ToNearestRect(anchor_f); |
59 gfx::Size viewport = ScaleToRoundedSize(view->viewport_size(), scale); | 54 gfx::Size viewport = ScaleToRoundedSize(view->viewport_size(), scale); |
60 | 55 |
61 JNIEnv* env = base::android::AttachCurrentThread(); | 56 JNIEnv* env = base::android::AttachCurrentThread(); |
62 Java_ValidationMessageBubble_showAtPositionRelativeToAnchor( | 57 Java_ValidationMessageBubble_showAtPositionRelativeToAnchor( |
63 env, java_validation_message_bubble_, viewport.width(), viewport.height(), | 58 env, java_validation_message_bubble_, viewport.width(), viewport.height(), |
64 view->content_offset() * scale, anchor.x(), anchor.y(), anchor.width(), | 59 view->content_offset() * scale, anchor.x(), anchor.y(), anchor.width(), |
65 anchor.height()); | 60 anchor.height()); |
66 } | 61 } |
67 | 62 |
68 } // namespace web_contents_delegate_android | 63 } // namespace web_contents_delegate_android |
OLD | NEW |