Apply _RELATIVE relocations ahead of others.
[chromium-blink-merge.git] / content / browser / android / content_view_core_impl.h
blob6e906960d07bd06784fafb0e399ea84d81046aea
1 // Copyright 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.
5 #ifndef CONTENT_BROWSER_ANDROID_CONTENT_VIEW_CORE_IMPL_H_
6 #define CONTENT_BROWSER_ANDROID_CONTENT_VIEW_CORE_IMPL_H_
8 #include <vector>
10 #include "base/android/jni_android.h"
11 #include "base/android/jni_weak_ref.h"
12 #include "base/compiler_specific.h"
13 #include "base/i18n/rtl.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/process/process.h"
16 #include "content/browser/renderer_host/render_widget_host_view_android.h"
17 #include "content/browser/web_contents/web_contents_impl.h"
18 #include "content/public/browser/android/content_view_core.h"
19 #include "content/public/browser/web_contents_observer.h"
20 #include "third_party/WebKit/public/web/WebInputEvent.h"
21 #include "ui/gfx/rect.h"
22 #include "ui/gfx/rect_f.h"
23 #include "url/gurl.h"
25 namespace ui {
26 class ViewAndroid;
27 class WindowAndroid;
30 namespace content {
32 class GinJavaBridgeDispatcherHost;
33 class RenderFrameHost;
34 class RenderWidgetHostViewAndroid;
35 struct MenuItem;
37 // TODO(jrg): this is a shell. Upstream the rest.
38 class ContentViewCoreImpl : public ContentViewCore,
39 public WebContentsObserver {
40 public:
41 static ContentViewCoreImpl* FromWebContents(WebContents* web_contents);
42 ContentViewCoreImpl(JNIEnv* env,
43 jobject obj,
44 WebContents* web_contents,
45 ui::ViewAndroid* view_android,
46 ui::WindowAndroid* window_android,
47 jobject java_bridge_retained_object_set);
49 // ContentViewCore implementation.
50 virtual base::android::ScopedJavaLocalRef<jobject> GetJavaObject() override;
51 virtual WebContents* GetWebContents() const override;
52 virtual ui::ViewAndroid* GetViewAndroid() const override;
53 virtual ui::WindowAndroid* GetWindowAndroid() const override;
54 virtual scoped_refptr<cc::Layer> GetLayer() const override;
55 virtual void ShowPastePopup(int x, int y) override;
56 virtual void GetScaledContentBitmap(
57 float scale,
58 SkColorType color_type,
59 gfx::Rect src_subrect,
60 const base::Callback<void(bool, const SkBitmap&)>& result_callback)
61 override;
62 virtual float GetDpiScale() const override;
63 virtual void PauseOrResumeGeolocation(bool should_pause) override;
64 virtual void RequestTextSurroundingSelection(
65 int max_length,
66 const base::Callback<void(const base::string16& content,
67 int start_offset,
68 int end_offset)>& callback) override;
70 // --------------------------------------------------------------------------
71 // Methods called from Java via JNI
72 // --------------------------------------------------------------------------
74 base::android::ScopedJavaLocalRef<jobject> GetWebContentsAndroid(JNIEnv* env,
75 jobject obj);
77 void OnJavaContentViewCoreDestroyed(JNIEnv* env, jobject obj);
79 // Notifies the ContentViewCore that items were selected in the currently
80 // showing select popup.
81 void SelectPopupMenuItems(JNIEnv* env, jobject obj,
82 jlong selectPopupSourceFrame,
83 jintArray indices);
85 void SendOrientationChangeEvent(JNIEnv* env, jobject obj, jint orientation);
86 jboolean OnTouchEvent(JNIEnv* env,
87 jobject obj,
88 jobject motion_event,
89 jlong time_ms,
90 jint android_action,
91 jint pointer_count,
92 jint history_size,
93 jint action_index,
94 jfloat pos_x_0,
95 jfloat pos_y_0,
96 jfloat pos_x_1,
97 jfloat pos_y_1,
98 jint pointer_id_0,
99 jint pointer_id_1,
100 jfloat touch_major_0,
101 jfloat touch_major_1,
102 jfloat touch_minor_0,
103 jfloat touch_minor_1,
104 jfloat orientation_0,
105 jfloat orientation_1,
106 jfloat raw_pos_x,
107 jfloat raw_pos_y,
108 jint android_tool_type_0,
109 jint android_tool_type_1,
110 jint android_button_state,
111 jint android_meta_state,
112 jboolean is_touch_handle_event);
113 jboolean SendMouseMoveEvent(JNIEnv* env,
114 jobject obj,
115 jlong time_ms,
116 jfloat x,
117 jfloat y);
118 jboolean SendMouseWheelEvent(JNIEnv* env,
119 jobject obj,
120 jlong time_ms,
121 jfloat x,
122 jfloat y,
123 jfloat vertical_axis);
124 void ScrollBegin(JNIEnv* env, jobject obj, jlong time_ms,
125 jfloat x, jfloat y, jfloat hintx, jfloat hinty);
126 void ScrollEnd(JNIEnv* env, jobject obj, jlong time_ms);
127 void ScrollBy(JNIEnv* env, jobject obj, jlong time_ms,
128 jfloat x, jfloat y, jfloat dx, jfloat dy);
129 void FlingStart(JNIEnv* env, jobject obj, jlong time_ms,
130 jfloat x, jfloat y, jfloat vx, jfloat vy);
131 void FlingCancel(JNIEnv* env, jobject obj, jlong time_ms);
132 void SingleTap(JNIEnv* env, jobject obj, jlong time_ms,
133 jfloat x, jfloat y);
134 void DoubleTap(JNIEnv* env, jobject obj, jlong time_ms,
135 jfloat x, jfloat y) ;
136 void LongPress(JNIEnv* env, jobject obj, jlong time_ms,
137 jfloat x, jfloat y);
138 void PinchBegin(JNIEnv* env, jobject obj, jlong time_ms, jfloat x, jfloat y);
139 void PinchEnd(JNIEnv* env, jobject obj, jlong time_ms);
140 void PinchBy(JNIEnv* env, jobject obj, jlong time_ms,
141 jfloat x, jfloat y, jfloat delta);
142 void SelectBetweenCoordinates(JNIEnv* env, jobject obj,
143 jfloat x1, jfloat y1,
144 jfloat x2, jfloat y2);
145 void MoveCaret(JNIEnv* env, jobject obj, jfloat x, jfloat y);
146 void HideTextHandles(JNIEnv* env, jobject obj);
148 void ResetGestureDetection(JNIEnv* env, jobject obj);
149 void SetDoubleTapSupportEnabled(JNIEnv* env, jobject obj, jboolean enabled);
150 void SetMultiTouchZoomSupportEnabled(JNIEnv* env,
151 jobject obj,
152 jboolean enabled);
154 long GetNativeImeAdapter(JNIEnv* env, jobject obj);
155 void SetFocus(JNIEnv* env, jobject obj, jboolean focused);
157 jint GetBackgroundColor(JNIEnv* env, jobject obj);
158 void SetBackgroundColor(JNIEnv* env, jobject obj, jint color);
159 void SetAllowJavascriptInterfacesInspection(JNIEnv* env,
160 jobject obj,
161 jboolean allow);
162 void AddJavascriptInterface(JNIEnv* env,
163 jobject obj,
164 jobject object,
165 jstring name,
166 jclass safe_annotation_clazz);
167 void RemoveJavascriptInterface(JNIEnv* env, jobject obj, jstring name);
168 void WasResized(JNIEnv* env, jobject obj);
170 void SetAccessibilityEnabled(JNIEnv* env, jobject obj, bool enabled);
172 void ExtractSmartClipData(JNIEnv* env,
173 jobject obj,
174 jint x,
175 jint y,
176 jint width,
177 jint height);
179 void SetBackgroundOpaque(JNIEnv* env, jobject jobj, jboolean opaque);
181 jint GetCurrentRenderProcessId(JNIEnv* env, jobject obj);
183 // --------------------------------------------------------------------------
184 // Public methods that call to Java via JNI
185 // --------------------------------------------------------------------------
187 void OnSmartClipDataExtracted(const base::string16& text,
188 const base::string16& html,
189 const gfx::Rect& clip_rect);
191 // Creates a popup menu with |items|.
192 // |multiple| defines if it should support multi-select.
193 // If not |multiple|, |selected_item| sets the initially selected item.
194 // Otherwise, item's "checked" flag selects it.
195 void ShowSelectPopupMenu(RenderFrameHost* frame,
196 const gfx::Rect& bounds,
197 const std::vector<MenuItem>& items,
198 int selected_item,
199 bool multiple);
200 // Hides a visible popup menu.
201 void HideSelectPopupMenu();
203 // All sizes and offsets are in CSS pixels as cached by the renderer.
204 void UpdateFrameInfo(const gfx::Vector2dF& scroll_offset,
205 float page_scale_factor,
206 const gfx::Vector2dF& page_scale_factor_limits,
207 const gfx::SizeF& content_size,
208 const gfx::SizeF& viewport_size,
209 const gfx::Vector2dF& controls_offset,
210 const gfx::Vector2dF& content_offset);
212 void UpdateImeAdapter(long native_ime_adapter,
213 int text_input_type,
214 int text_input_flags,
215 const std::string& text,
216 int selection_start,
217 int selection_end,
218 int composition_start,
219 int composition_end,
220 bool show_ime_if_needed,
221 bool is_non_ime_change);
222 void SetTitle(const base::string16& title);
223 void OnBackgroundColorChanged(SkColor color);
225 bool HasFocus();
226 void OnGestureEventAck(const blink::WebGestureEvent& event,
227 InputEventAckState ack_result);
228 bool FilterInputEvent(const blink::WebInputEvent& event);
229 void OnSelectionChanged(const std::string& text);
230 void OnSelectionEvent(SelectionEventType event,
231 const gfx::PointF& anchor_position);
232 scoped_ptr<TouchHandleDrawable> CreatePopupTouchHandleDrawable();
234 void StartContentIntent(const GURL& content_url);
236 // Shows the disambiguation popup
237 // |rect_pixels| --> window coordinates which |zoomed_bitmap| represents
238 // |zoomed_bitmap| --> magnified image of potential touch targets
239 void ShowDisambiguationPopup(
240 const gfx::Rect& rect_pixels, const SkBitmap& zoomed_bitmap);
242 // Creates a java-side touch event, used for injecting touch event for
243 // testing/benchmarking purposes
244 base::android::ScopedJavaLocalRef<jobject> CreateTouchEventSynthesizer();
246 // Returns True if the given media should be blocked to load.
247 bool ShouldBlockMediaRequest(const GURL& url);
249 void DidStopFlinging();
251 // Returns the context with which the ContentViewCore was created, typically
252 // the Activity context.
253 base::android::ScopedJavaLocalRef<jobject> GetContext() const;
255 // Returns the viewport size after accounting for the viewport offset.
256 gfx::Size GetViewSize() const;
258 void SetAccessibilityEnabledInternal(bool enabled);
260 bool IsFullscreenRequiredForOrientationLock() const;
262 // --------------------------------------------------------------------------
263 // Methods called from native code
264 // --------------------------------------------------------------------------
266 gfx::Size GetPhysicalBackingSize() const;
267 gfx::Size GetViewportSizeDip() const;
268 float GetTopControlsLayoutHeightDip() const;
270 void AttachLayer(scoped_refptr<cc::Layer> layer);
271 void RemoveLayer(scoped_refptr<cc::Layer> layer);
273 void MoveRangeSelectionExtent(const gfx::PointF& extent);
275 void SelectBetweenCoordinates(const gfx::PointF& base,
276 const gfx::PointF& extent);
278 private:
279 class ContentViewUserData;
281 friend class ContentViewUserData;
282 virtual ~ContentViewCoreImpl();
284 // WebContentsObserver implementation.
285 virtual void RenderViewReady() override;
286 virtual void RenderViewHostChanged(RenderViewHost* old_host,
287 RenderViewHost* new_host) override;
288 virtual void WebContentsDestroyed() override;
290 // --------------------------------------------------------------------------
291 // Other private methods and data
292 // --------------------------------------------------------------------------
294 void InitWebContents();
296 RenderWidgetHostViewAndroid* GetRenderWidgetHostViewAndroid();
298 blink::WebGestureEvent MakeGestureEvent(
299 blink::WebInputEvent::Type type, int64 time_ms, float x, float y) const;
301 gfx::Size GetViewportSizePix() const;
302 int GetTopControlsLayoutHeightPix() const;
304 void SendGestureEvent(const blink::WebGestureEvent& event);
306 // Update focus state of the RenderWidgetHostView.
307 void SetFocusInternal(bool focused);
309 // Send device_orientation_ to renderer.
310 void SendOrientationChangeEventInternal();
312 float dpi_scale() const { return dpi_scale_; }
314 // A weak reference to the Java ContentViewCore object.
315 JavaObjectWeakGlobalRef java_ref_;
317 // Reference to the current WebContents used to determine how and what to
318 // display in the ContentViewCore.
319 WebContentsImpl* web_contents_;
321 // A compositor layer containing any layer that should be shown.
322 scoped_refptr<cc::Layer> root_layer_;
324 // Device scale factor.
325 float dpi_scale_;
327 // The Android view that can be used to add and remove decoration layers
328 // like AutofillPopup.
329 ui::ViewAndroid* view_android_;
331 // The owning window that has a hold of main application activity.
332 ui::WindowAndroid* window_android_;
334 // The cache of device's current orientation set from Java side, this value
335 // will be sent to Renderer once it is ready.
336 int device_orientation_;
338 bool accessibility_enabled_;
340 // Manages injecting Java objects.
341 scoped_ptr<GinJavaBridgeDispatcherHost>
342 java_bridge_dispatcher_host_;
344 DISALLOW_COPY_AND_ASSIGN(ContentViewCoreImpl);
347 bool RegisterContentViewCore(JNIEnv* env);
349 } // namespace content
351 #endif // CONTENT_BROWSER_ANDROID_CONTENT_VIEW_CORE_IMPL_H_