Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / content / browser / android / content_view_core_impl.h
blob0ac6d75e92cf8146229ea94d067d01240e4fa2da
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);
266 scoped_ptr<ui::TouchHandleDrawable> CreatePopupTouchHandleDrawable();
268 void StartContentIntent(const GURL& content_url);
270 // Shows the disambiguation popup
271 // |rect_pixels| --> window coordinates which |zoomed_bitmap| represents
272 // |zoomed_bitmap| --> magnified image of potential touch targets
273 void ShowDisambiguationPopup(
274 const gfx::Rect& rect_pixels, const SkBitmap& zoomed_bitmap);
276 // Creates a java-side touch event, used for injecting motion events for
277 // testing/benchmarking purposes.
278 base::android::ScopedJavaLocalRef<jobject> CreateMotionEventSynthesizer();
280 // Returns True if the given media should be blocked to load.
281 bool ShouldBlockMediaRequest(const GURL& url);
283 void DidStopFlinging();
285 // Returns the context with which the ContentViewCore was created, typically
286 // the Activity context.
287 base::android::ScopedJavaLocalRef<jobject> GetContext() const;
289 // Returns the viewport size after accounting for the viewport offset.
290 gfx::Size GetViewSize() const;
292 void SetAccessibilityEnabledInternal(bool enabled);
294 bool IsFullscreenRequiredForOrientationLock() const;
296 // --------------------------------------------------------------------------
297 // Methods called from native code
298 // --------------------------------------------------------------------------
300 gfx::Size GetPhysicalBackingSize() const;
301 gfx::Size GetViewportSizeDip() const;
302 bool DoTopControlsShrinkBlinkSize() const;
303 float GetTopControlsHeightDip() const;
305 void AttachLayer(scoped_refptr<cc::Layer> layer);
306 void RemoveLayer(scoped_refptr<cc::Layer> layer);
308 void MoveRangeSelectionExtent(const gfx::PointF& extent);
310 void SelectBetweenCoordinates(const gfx::PointF& base,
311 const gfx::PointF& extent);
313 void OnShowUnhandledTapUIIfNeeded(int x_dip, int y_dip);
315 // returns page density (dpi) X page scale
316 float GetScaleFactor() const;
317 private:
318 class ContentViewUserData;
320 friend class ContentViewUserData;
321 ~ContentViewCoreImpl() override;
323 // WebContentsObserver implementation.
324 void RenderViewReady() override;
325 void RenderViewHostChanged(RenderViewHost* old_host,
326 RenderViewHost* new_host) override;
327 void WebContentsDestroyed() override;
329 // OverscrollRefreshHandler implementation.
330 bool PullStart() override;
331 void PullUpdate(float delta) override;
332 void PullRelease(bool allow_refresh) override;
333 void PullReset() override;
335 // --------------------------------------------------------------------------
336 // Other private methods and data
337 // --------------------------------------------------------------------------
339 void InitWebContents();
341 RenderWidgetHostViewAndroid* GetRenderWidgetHostViewAndroid() const;
343 blink::WebGestureEvent MakeGestureEvent(
344 blink::WebInputEvent::Type type, int64 time_ms, float x, float y) const;
346 gfx::Size GetViewportSizePix() const;
347 int GetTopControlsHeightPix() const;
349 void SendGestureEvent(const blink::WebGestureEvent& event);
351 // Update focus state of the RenderWidgetHostView.
352 void SetFocusInternal(bool focused);
354 // Send device_orientation_ to renderer.
355 void SendOrientationChangeEventInternal();
357 float dpi_scale() const { return dpi_scale_; }
359 // A weak reference to the Java ContentViewCore object.
360 JavaObjectWeakGlobalRef java_ref_;
362 // Reference to the current WebContents used to determine how and what to
363 // display in the ContentViewCore.
364 WebContentsImpl* web_contents_;
366 // A compositor layer containing any layer that should be shown.
367 scoped_refptr<cc::Layer> root_layer_;
369 // Page scale factor.
370 float page_scale_;
372 // The Android view that can be used to add and remove decoration layers
373 // like AutofillPopup.
374 scoped_ptr<ui::ViewAndroid> view_android_;
376 // Device scale factor.
377 const float dpi_scale_;
379 // The owning window that has a hold of main application activity.
380 ui::WindowAndroid* window_android_;
382 // The cache of device's current orientation set from Java side, this value
383 // will be sent to Renderer once it is ready.
384 int device_orientation_;
386 bool accessibility_enabled_;
388 // Manages injecting Java objects.
389 scoped_refptr<GinJavaBridgeDispatcherHost> java_bridge_dispatcher_host_;
391 DISALLOW_COPY_AND_ASSIGN(ContentViewCoreImpl);
394 bool RegisterContentViewCore(JNIEnv* env);
396 } // namespace content
398 #endif // CONTENT_BROWSER_ANDROID_CONTENT_VIEW_CORE_IMPL_H_