[refactor] More post-NSS WebCrypto cleanups (utility functions).
[chromium-blink-merge.git] / content / browser / android / content_view_core_impl.h
blobfe0bcd8da7bc2d484f4d31a24ebcc80ae692ae89
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/android/overscroll_refresh.h"
17 #include "content/browser/renderer_host/render_widget_host_view_android.h"
18 #include "content/browser/web_contents/web_contents_impl.h"
19 #include "content/public/browser/android/content_view_core.h"
20 #include "content/public/browser/web_contents_observer.h"
21 #include "third_party/WebKit/public/web/WebInputEvent.h"
22 #include "ui/gfx/geometry/rect.h"
23 #include "ui/gfx/geometry/rect_f.h"
24 #include "url/gurl.h"
26 namespace ui {
27 class ViewAndroid;
28 class WindowAndroid;
31 namespace content {
33 class GinJavaBridgeDispatcherHost;
34 class RenderFrameHost;
35 class RenderWidgetHostViewAndroid;
36 struct MenuItem;
38 class ContentViewCoreImpl : public ContentViewCore,
39 public OverscrollRefreshHandler,
40 public WebContentsObserver {
41 public:
42 static ContentViewCoreImpl* FromWebContents(WebContents* web_contents);
43 ContentViewCoreImpl(JNIEnv* env,
44 jobject obj,
45 WebContents* web_contents,
46 jobject view_android,
47 ui::WindowAndroid* window_android,
48 jobject java_bridge_retained_object_set);
50 // ContentViewCore implementation.
51 base::android::ScopedJavaLocalRef<jobject> GetJavaObject() override;
52 WebContents* GetWebContents() const override;
53 ui::ViewAndroid* GetViewAndroid() const override;
54 ui::WindowAndroid* GetWindowAndroid() const override;
55 const scoped_refptr<cc::Layer>& GetLayer() const override;
56 void ShowPastePopup(int x, int y) override;
57 void GetScaledContentBitmap(
58 float scale,
59 SkColorType preferred_color_type,
60 const gfx::Rect& src_subrect,
61 ReadbackRequestCallback& result_callback) override;
62 float GetDpiScale() const override;
63 void PauseOrResumeGeolocation(bool should_pause) override;
64 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);
76 base::android::ScopedJavaLocalRef<jobject> GetJavaWindowAndroid(JNIEnv* env,
77 jobject obj);
79 void OnJavaContentViewCoreDestroyed(JNIEnv* env, jobject obj);
81 // Notifies the ContentViewCore that items were selected in the currently
82 // showing select popup.
83 void SelectPopupMenuItems(JNIEnv* env, jobject obj,
84 jlong selectPopupSourceFrame,
85 jintArray indices);
87 void SendOrientationChangeEvent(JNIEnv* env, jobject obj, jint orientation);
88 jboolean OnTouchEvent(JNIEnv* env,
89 jobject obj,
90 jobject motion_event,
91 jlong time_ms,
92 jint android_action,
93 jint pointer_count,
94 jint history_size,
95 jint action_index,
96 jfloat pos_x_0,
97 jfloat pos_y_0,
98 jfloat pos_x_1,
99 jfloat pos_y_1,
100 jint pointer_id_0,
101 jint pointer_id_1,
102 jfloat touch_major_0,
103 jfloat touch_major_1,
104 jfloat touch_minor_0,
105 jfloat touch_minor_1,
106 jfloat orientation_0,
107 jfloat orientation_1,
108 jfloat raw_pos_x,
109 jfloat raw_pos_y,
110 jint android_tool_type_0,
111 jint android_tool_type_1,
112 jint android_button_state,
113 jint android_meta_state,
114 jboolean is_touch_handle_event);
115 jboolean SendMouseMoveEvent(JNIEnv* env,
116 jobject obj,
117 jlong time_ms,
118 jfloat x,
119 jfloat y);
120 jboolean SendMouseWheelEvent(JNIEnv* env,
121 jobject obj,
122 jlong time_ms,
123 jfloat x,
124 jfloat y,
125 jfloat ticks_x,
126 jfloat ticks_y,
127 jfloat pixels_per_tick);
128 void ScrollBegin(JNIEnv* env,
129 jobject obj,
130 jlong time_ms,
131 jfloat x,
132 jfloat y,
133 jfloat hintx,
134 jfloat hinty,
135 jboolean target_viewport);
136 void ScrollEnd(JNIEnv* env, jobject obj, jlong time_ms);
137 void ScrollBy(JNIEnv* env, jobject obj, jlong time_ms,
138 jfloat x, jfloat y, jfloat dx, jfloat dy);
139 void FlingStart(JNIEnv* env,
140 jobject obj,
141 jlong time_ms,
142 jfloat x,
143 jfloat y,
144 jfloat vx,
145 jfloat vy,
146 jboolean target_viewport);
147 void FlingCancel(JNIEnv* env, jobject obj, jlong time_ms);
148 void SingleTap(JNIEnv* env, jobject obj, jlong time_ms,
149 jfloat x, jfloat y);
150 void DoubleTap(JNIEnv* env, jobject obj, jlong time_ms,
151 jfloat x, jfloat y) ;
152 void LongPress(JNIEnv* env, jobject obj, jlong time_ms,
153 jfloat x, jfloat y);
154 void PinchBegin(JNIEnv* env, jobject obj, jlong time_ms, jfloat x, jfloat y);
155 void PinchEnd(JNIEnv* env, jobject obj, jlong time_ms);
156 void PinchBy(JNIEnv* env, jobject obj, jlong time_ms,
157 jfloat x, jfloat y, jfloat delta);
158 void SelectBetweenCoordinates(JNIEnv* env, jobject obj,
159 jfloat x1, jfloat y1,
160 jfloat x2, jfloat y2);
161 void MoveCaret(JNIEnv* env, jobject obj, jfloat x, jfloat y);
162 void DismissTextHandles(JNIEnv* env, jobject obj);
163 void SetTextHandlesTemporarilyHidden(JNIEnv* env,
164 jobject obj,
165 jboolean hidden);
167 void ResetGestureDetection(JNIEnv* env, jobject obj);
168 void SetDoubleTapSupportEnabled(JNIEnv* env, jobject obj, jboolean enabled);
169 void SetMultiTouchZoomSupportEnabled(JNIEnv* env,
170 jobject obj,
171 jboolean enabled);
173 long GetNativeImeAdapter(JNIEnv* env, jobject obj);
174 void SetFocus(JNIEnv* env, jobject obj, jboolean focused);
176 jint GetBackgroundColor(JNIEnv* env, jobject obj);
177 void SetBackgroundColor(JNIEnv* env, jobject obj, jint color);
178 void SetAllowJavascriptInterfacesInspection(JNIEnv* env,
179 jobject obj,
180 jboolean allow);
181 void AddJavascriptInterface(JNIEnv* env,
182 jobject obj,
183 jobject object,
184 jstring name,
185 jclass safe_annotation_clazz);
186 void RemoveJavascriptInterface(JNIEnv* env, jobject obj, jstring name);
187 void WasResized(JNIEnv* env, jobject obj);
189 void SetAccessibilityEnabled(JNIEnv* env, jobject obj, bool enabled);
191 void SetTextTrackSettings(JNIEnv* env,
192 jobject obj,
193 jboolean textTracksEnabled,
194 jstring textTrackBackgroundColor,
195 jstring textTrackFontFamily,
196 jstring textTrackFontStyle,
197 jstring textTrackFontVariant,
198 jstring textTrackTextColor,
199 jstring textTrackTextShadow,
200 jstring textTrackTextSize);
202 void ExtractSmartClipData(JNIEnv* env,
203 jobject obj,
204 jint x,
205 jint y,
206 jint width,
207 jint height);
209 void SetBackgroundOpaque(JNIEnv* env, jobject jobj, jboolean opaque);
211 jint GetCurrentRenderProcessId(JNIEnv* env, jobject obj);
213 // --------------------------------------------------------------------------
214 // Public methods that call to Java via JNI
215 // --------------------------------------------------------------------------
217 void OnSmartClipDataExtracted(const base::string16& text,
218 const base::string16& html,
219 const gfx::Rect& clip_rect);
221 // Creates a popup menu with |items|.
222 // |multiple| defines if it should support multi-select.
223 // If not |multiple|, |selected_item| sets the initially selected item.
224 // Otherwise, item's "checked" flag selects it.
225 void ShowSelectPopupMenu(RenderFrameHost* frame,
226 const gfx::Rect& bounds,
227 const std::vector<MenuItem>& items,
228 int selected_item,
229 bool multiple);
230 // Hides a visible popup menu.
231 void HideSelectPopupMenu();
233 // All sizes and offsets are in CSS pixels as cached by the renderer.
234 void UpdateFrameInfo(const gfx::Vector2dF& scroll_offset,
235 float page_scale_factor,
236 const gfx::Vector2dF& page_scale_factor_limits,
237 const gfx::SizeF& content_size,
238 const gfx::SizeF& viewport_size,
239 const gfx::Vector2dF& controls_offset,
240 const gfx::Vector2dF& content_offset,
241 bool is_mobile_optimized_hint);
243 void ForceUpdateImeAdapter(long native_ime_adapter);
244 void UpdateImeAdapter(long native_ime_adapter,
245 int text_input_type,
246 int text_input_flags,
247 const std::string& text,
248 int selection_start,
249 int selection_end,
250 int composition_start,
251 int composition_end,
252 bool show_ime_if_needed,
253 bool is_non_ime_change);
254 void SetTitle(const base::string16& title);
255 void OnBackgroundColorChanged(SkColor color);
257 bool HasFocus();
258 void RequestDisallowInterceptTouchEvent();
259 void OnGestureEventAck(const blink::WebGestureEvent& event,
260 InputEventAckState ack_result);
261 bool FilterInputEvent(const blink::WebInputEvent& event);
262 void OnSelectionChanged(const std::string& text);
263 void OnSelectionEvent(ui::SelectionEventType event,
264 const gfx::PointF& selection_anchor,
265 const gfx::RectF& selection_rect);
267 void StartContentIntent(const GURL& content_url);
269 // Shows the disambiguation popup
270 // |rect_pixels| --> window coordinates which |zoomed_bitmap| represents
271 // |zoomed_bitmap| --> magnified image of potential touch targets
272 void ShowDisambiguationPopup(
273 const gfx::Rect& rect_pixels, const SkBitmap& zoomed_bitmap);
275 // Creates a java-side touch event, used for injecting motion events for
276 // testing/benchmarking purposes.
277 base::android::ScopedJavaLocalRef<jobject> CreateMotionEventSynthesizer();
279 // Returns True if the given media should be blocked to load.
280 bool ShouldBlockMediaRequest(const GURL& url);
282 void DidStopFlinging();
284 // Returns the context with which the ContentViewCore was created, typically
285 // the Activity context.
286 base::android::ScopedJavaLocalRef<jobject> GetContext() const;
288 // Returns the viewport size after accounting for the viewport offset.
289 gfx::Size GetViewSize() const;
291 void SetAccessibilityEnabledInternal(bool enabled);
293 bool IsFullscreenRequiredForOrientationLock() const;
295 // --------------------------------------------------------------------------
296 // Methods called from native code
297 // --------------------------------------------------------------------------
299 gfx::Size GetPhysicalBackingSize() const;
300 gfx::Size GetViewportSizeDip() const;
301 bool DoTopControlsShrinkBlinkSize() const;
302 float GetTopControlsHeightDip() const;
304 void AttachLayer(scoped_refptr<cc::Layer> layer);
305 void RemoveLayer(scoped_refptr<cc::Layer> layer);
307 void MoveRangeSelectionExtent(const gfx::PointF& extent);
309 void SelectBetweenCoordinates(const gfx::PointF& base,
310 const gfx::PointF& extent);
312 void OnShowUnhandledTapUIIfNeeded(int x_dip, int y_dip);
314 // returns page density (dpi) X page scale
315 float GetScaleFactor() const;
316 private:
317 class ContentViewUserData;
319 friend class ContentViewUserData;
320 ~ContentViewCoreImpl() override;
322 // WebContentsObserver implementation.
323 void RenderViewReady() override;
324 void RenderViewHostChanged(RenderViewHost* old_host,
325 RenderViewHost* new_host) override;
326 void WebContentsDestroyed() override;
328 // OverscrollRefreshHandler implementation.
329 bool PullStart() override;
330 void PullUpdate(float delta) override;
331 void PullRelease(bool allow_refresh) override;
332 void PullReset() override;
334 // --------------------------------------------------------------------------
335 // Other private methods and data
336 // --------------------------------------------------------------------------
338 void InitWebContents();
340 RenderWidgetHostViewAndroid* GetRenderWidgetHostViewAndroid() const;
342 blink::WebGestureEvent MakeGestureEvent(
343 blink::WebInputEvent::Type type, int64 time_ms, float x, float y) const;
345 gfx::Size GetViewportSizePix() const;
346 int GetTopControlsHeightPix() const;
348 void SendGestureEvent(const blink::WebGestureEvent& event);
350 // Update focus state of the RenderWidgetHostView.
351 void SetFocusInternal(bool focused);
353 // Send device_orientation_ to renderer.
354 void SendOrientationChangeEventInternal();
356 float dpi_scale() const { return dpi_scale_; }
358 // A weak reference to the Java ContentViewCore object.
359 JavaObjectWeakGlobalRef java_ref_;
361 // Reference to the current WebContents used to determine how and what to
362 // display in the ContentViewCore.
363 WebContentsImpl* web_contents_;
365 // A compositor layer containing any layer that should be shown.
366 scoped_refptr<cc::Layer> root_layer_;
368 // Page scale factor.
369 float page_scale_;
371 // The Android view that can be used to add and remove decoration layers
372 // like AutofillPopup.
373 scoped_ptr<ui::ViewAndroid> view_android_;
375 // Device scale factor.
376 const float dpi_scale_;
378 // The owning window that has a hold of main application activity.
379 ui::WindowAndroid* window_android_;
381 // The cache of device's current orientation set from Java side, this value
382 // will be sent to Renderer once it is ready.
383 int device_orientation_;
385 bool accessibility_enabled_;
387 // Manages injecting Java objects.
388 scoped_refptr<GinJavaBridgeDispatcherHost> java_bridge_dispatcher_host_;
390 DISALLOW_COPY_AND_ASSIGN(ContentViewCoreImpl);
393 bool RegisterContentViewCore(JNIEnv* env);
395 } // namespace content
397 #endif // CONTENT_BROWSER_ANDROID_CONTENT_VIEW_CORE_IMPL_H_