Android Chromoting: Remove exit-fullscreen button.
[chromium-blink-merge.git] / content / browser / android / content_view_core_impl.h
blob2b936a1c9cc10f63f1510d33e3890c9b2dc2b09a
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/geometry/rect.h"
22 #include "ui/gfx/geometry/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 class ContentViewCoreImpl : public ContentViewCore,
38 public WebContentsObserver {
39 public:
40 static ContentViewCoreImpl* FromWebContents(WebContents* web_contents);
41 ContentViewCoreImpl(JNIEnv* env,
42 jobject obj,
43 WebContents* web_contents,
44 jobject view_android,
45 ui::WindowAndroid* window_android,
46 jobject java_bridge_retained_object_set);
48 // ContentViewCore implementation.
49 base::android::ScopedJavaLocalRef<jobject> GetJavaObject() override;
50 WebContents* GetWebContents() const override;
51 ui::ViewAndroid* GetViewAndroid() const override;
52 ui::WindowAndroid* GetWindowAndroid() const override;
53 const scoped_refptr<cc::Layer>& GetLayer() const override;
54 void ShowPastePopup(int x, int y) override;
55 void GetScaledContentBitmap(
56 float scale,
57 SkColorType color_type,
58 gfx::Rect src_subrect,
59 ReadbackRequestCallback& result_callback) override;
60 float GetDpiScale() const override;
61 void PauseOrResumeGeolocation(bool should_pause) override;
62 void RequestTextSurroundingSelection(
63 int max_length,
64 const base::Callback<void(const base::string16& content,
65 int start_offset,
66 int end_offset)>& callback) override;
68 // --------------------------------------------------------------------------
69 // Methods called from Java via JNI
70 // --------------------------------------------------------------------------
72 base::android::ScopedJavaLocalRef<jobject> GetWebContentsAndroid(JNIEnv* env,
73 jobject obj);
75 void OnJavaContentViewCoreDestroyed(JNIEnv* env, jobject obj);
77 // Notifies the ContentViewCore that items were selected in the currently
78 // showing select popup.
79 void SelectPopupMenuItems(JNIEnv* env, jobject obj,
80 jlong selectPopupSourceFrame,
81 jintArray indices);
83 void SendOrientationChangeEvent(JNIEnv* env, jobject obj, jint orientation);
84 jboolean OnTouchEvent(JNIEnv* env,
85 jobject obj,
86 jobject motion_event,
87 jlong time_ms,
88 jint android_action,
89 jint pointer_count,
90 jint history_size,
91 jint action_index,
92 jfloat pos_x_0,
93 jfloat pos_y_0,
94 jfloat pos_x_1,
95 jfloat pos_y_1,
96 jint pointer_id_0,
97 jint pointer_id_1,
98 jfloat touch_major_0,
99 jfloat touch_major_1,
100 jfloat touch_minor_0,
101 jfloat touch_minor_1,
102 jfloat orientation_0,
103 jfloat orientation_1,
104 jfloat raw_pos_x,
105 jfloat raw_pos_y,
106 jint android_tool_type_0,
107 jint android_tool_type_1,
108 jint android_button_state,
109 jint android_meta_state,
110 jboolean is_touch_handle_event);
111 jboolean SendMouseMoveEvent(JNIEnv* env,
112 jobject obj,
113 jlong time_ms,
114 jfloat x,
115 jfloat y);
116 jboolean SendMouseWheelEvent(JNIEnv* env,
117 jobject obj,
118 jlong time_ms,
119 jfloat x,
120 jfloat y,
121 jfloat vertical_axis,
122 jfloat horizontal_axis);
123 void ScrollBegin(JNIEnv* env, jobject obj, jlong time_ms,
124 jfloat x, jfloat y, jfloat hintx, jfloat hinty);
125 void ScrollEnd(JNIEnv* env, jobject obj, jlong time_ms);
126 void ScrollBy(JNIEnv* env, jobject obj, jlong time_ms,
127 jfloat x, jfloat y, jfloat dx, jfloat dy);
128 void FlingStart(JNIEnv* env, jobject obj, jlong time_ms,
129 jfloat x, jfloat y, jfloat vx, jfloat vy);
130 void FlingCancel(JNIEnv* env, jobject obj, jlong time_ms);
131 void SingleTap(JNIEnv* env, jobject obj, jlong time_ms,
132 jfloat x, jfloat y);
133 void DoubleTap(JNIEnv* env, jobject obj, jlong time_ms,
134 jfloat x, jfloat y) ;
135 void LongPress(JNIEnv* env, jobject obj, jlong time_ms,
136 jfloat x, jfloat y);
137 void PinchBegin(JNIEnv* env, jobject obj, jlong time_ms, jfloat x, jfloat y);
138 void PinchEnd(JNIEnv* env, jobject obj, jlong time_ms);
139 void PinchBy(JNIEnv* env, jobject obj, jlong time_ms,
140 jfloat x, jfloat y, jfloat delta);
141 void SelectBetweenCoordinates(JNIEnv* env, jobject obj,
142 jfloat x1, jfloat y1,
143 jfloat x2, jfloat y2);
144 void MoveCaret(JNIEnv* env, jobject obj, jfloat x, jfloat y);
145 void DismissTextHandles(JNIEnv* env, jobject obj);
146 void SetTextHandlesTemporarilyHidden(JNIEnv* env,
147 jobject obj,
148 jboolean hidden);
150 void ResetGestureDetection(JNIEnv* env, jobject obj);
151 void SetDoubleTapSupportEnabled(JNIEnv* env, jobject obj, jboolean enabled);
152 void SetMultiTouchZoomSupportEnabled(JNIEnv* env,
153 jobject obj,
154 jboolean enabled);
156 long GetNativeImeAdapter(JNIEnv* env, jobject obj);
157 void SetFocus(JNIEnv* env, jobject obj, jboolean focused);
159 jint GetBackgroundColor(JNIEnv* env, jobject obj);
160 void SetBackgroundColor(JNIEnv* env, jobject obj, jint color);
161 void SetAllowJavascriptInterfacesInspection(JNIEnv* env,
162 jobject obj,
163 jboolean allow);
164 void AddJavascriptInterface(JNIEnv* env,
165 jobject obj,
166 jobject object,
167 jstring name,
168 jclass safe_annotation_clazz);
169 void RemoveJavascriptInterface(JNIEnv* env, jobject obj, jstring name);
170 void WasResized(JNIEnv* env, jobject obj);
172 void SetAccessibilityEnabled(JNIEnv* env, jobject obj, bool enabled);
174 void SetTextTrackSettings(JNIEnv* env,
175 jobject obj,
176 jstring textTrackBackgroundColor,
177 jstring textTrackFontFamily,
178 jstring textTrackFontStyle,
179 jstring textTrackFontVariant,
180 jstring textTrackTextColor,
181 jstring textTrackTextShadow,
182 jstring textTrackTextSize);
184 void ExtractSmartClipData(JNIEnv* env,
185 jobject obj,
186 jint x,
187 jint y,
188 jint width,
189 jint height);
191 void SetBackgroundOpaque(JNIEnv* env, jobject jobj, jboolean opaque);
192 void SetDrawsContent(JNIEnv* env, jobject jobj, jboolean draws);
194 jint GetCurrentRenderProcessId(JNIEnv* env, jobject obj);
196 // --------------------------------------------------------------------------
197 // Public methods that call to Java via JNI
198 // --------------------------------------------------------------------------
200 void OnSmartClipDataExtracted(const base::string16& text,
201 const base::string16& html,
202 const gfx::Rect& clip_rect);
204 // Creates a popup menu with |items|.
205 // |multiple| defines if it should support multi-select.
206 // If not |multiple|, |selected_item| sets the initially selected item.
207 // Otherwise, item's "checked" flag selects it.
208 void ShowSelectPopupMenu(RenderFrameHost* frame,
209 const gfx::Rect& bounds,
210 const std::vector<MenuItem>& items,
211 int selected_item,
212 bool multiple);
213 // Hides a visible popup menu.
214 void HideSelectPopupMenu();
216 // All sizes and offsets are in CSS pixels as cached by the renderer.
217 void UpdateFrameInfo(const gfx::Vector2dF& scroll_offset,
218 float page_scale_factor,
219 const gfx::Vector2dF& page_scale_factor_limits,
220 const gfx::SizeF& content_size,
221 const gfx::SizeF& viewport_size,
222 const gfx::Vector2dF& controls_offset,
223 const gfx::Vector2dF& content_offset,
224 bool is_mobile_optimized_hint);
226 void UpdateImeAdapter(long native_ime_adapter,
227 int text_input_type,
228 int text_input_flags,
229 const std::string& text,
230 int selection_start,
231 int selection_end,
232 int composition_start,
233 int composition_end,
234 bool show_ime_if_needed,
235 bool is_non_ime_change);
236 void SetTitle(const base::string16& title);
237 void OnBackgroundColorChanged(SkColor color);
239 bool HasFocus();
240 void OnGestureEventAck(const blink::WebGestureEvent& event,
241 InputEventAckState ack_result);
242 bool FilterInputEvent(const blink::WebInputEvent& event);
243 void OnSelectionChanged(const std::string& text);
244 void OnSelectionEvent(ui::SelectionEventType event,
245 const gfx::PointF& anchor_position);
246 scoped_ptr<ui::TouchHandleDrawable> CreatePopupTouchHandleDrawable();
248 void StartContentIntent(const GURL& content_url);
250 // Shows the disambiguation popup
251 // |rect_pixels| --> window coordinates which |zoomed_bitmap| represents
252 // |zoomed_bitmap| --> magnified image of potential touch targets
253 void ShowDisambiguationPopup(
254 const gfx::Rect& rect_pixels, const SkBitmap& zoomed_bitmap);
256 // Creates a java-side touch event, used for injecting touch event for
257 // testing/benchmarking purposes
258 base::android::ScopedJavaLocalRef<jobject> CreateTouchEventSynthesizer();
260 // Returns True if the given media should be blocked to load.
261 bool ShouldBlockMediaRequest(const GURL& url);
263 void DidStopFlinging();
265 // Returns the context with which the ContentViewCore was created, typically
266 // the Activity context.
267 base::android::ScopedJavaLocalRef<jobject> GetContext() const;
269 // Returns the viewport size after accounting for the viewport offset.
270 gfx::Size GetViewSize() const;
272 void SetAccessibilityEnabledInternal(bool enabled);
274 bool IsFullscreenRequiredForOrientationLock() const;
276 // --------------------------------------------------------------------------
277 // Methods called from native code
278 // --------------------------------------------------------------------------
280 gfx::Size GetPhysicalBackingSize() const;
281 gfx::Size GetViewportSizeDip() const;
282 bool DoTopControlsShrinkBlinkSize() const;
283 float GetTopControlsHeightDip() const;
285 void AttachLayer(scoped_refptr<cc::Layer> layer);
286 void RemoveLayer(scoped_refptr<cc::Layer> layer);
288 void MoveRangeSelectionExtent(const gfx::PointF& extent);
290 void SelectBetweenCoordinates(const gfx::PointF& base,
291 const gfx::PointF& extent);
293 void OnShowUnhandledTapUIIfNeeded(int x_dip, int y_dip);
295 private:
296 class ContentViewUserData;
298 friend class ContentViewUserData;
299 ~ContentViewCoreImpl() override;
301 // WebContentsObserver implementation.
302 void RenderViewReady() override;
303 void RenderViewHostChanged(RenderViewHost* old_host,
304 RenderViewHost* new_host) override;
305 void WebContentsDestroyed() override;
307 // --------------------------------------------------------------------------
308 // Other private methods and data
309 // --------------------------------------------------------------------------
311 void InitWebContents();
313 RenderWidgetHostViewAndroid* GetRenderWidgetHostViewAndroid() const;
315 blink::WebGestureEvent MakeGestureEvent(
316 blink::WebInputEvent::Type type, int64 time_ms, float x, float y) const;
318 gfx::Size GetViewportSizePix() const;
319 int GetTopControlsHeightPix() const;
321 void SendGestureEvent(const blink::WebGestureEvent& event);
323 // Update focus state of the RenderWidgetHostView.
324 void SetFocusInternal(bool focused);
326 // Send device_orientation_ to renderer.
327 void SendOrientationChangeEventInternal();
329 float dpi_scale() const { return dpi_scale_; }
331 // A weak reference to the Java ContentViewCore object.
332 JavaObjectWeakGlobalRef java_ref_;
334 // Reference to the current WebContents used to determine how and what to
335 // display in the ContentViewCore.
336 WebContentsImpl* web_contents_;
338 // A compositor layer containing any layer that should be shown.
339 scoped_refptr<cc::Layer> root_layer_;
341 // Device scale factor.
342 float dpi_scale_;
344 // The Android view that can be used to add and remove decoration layers
345 // like AutofillPopup.
346 scoped_ptr<ui::ViewAndroid> view_android_;
348 // The owning window that has a hold of main application activity.
349 ui::WindowAndroid* window_android_;
351 // The cache of device's current orientation set from Java side, this value
352 // will be sent to Renderer once it is ready.
353 int device_orientation_;
355 bool accessibility_enabled_;
357 // Manages injecting Java objects.
358 scoped_refptr<GinJavaBridgeDispatcherHost> java_bridge_dispatcher_host_;
360 DISALLOW_COPY_AND_ASSIGN(ContentViewCoreImpl);
363 bool RegisterContentViewCore(JNIEnv* env);
365 } // namespace content
367 #endif // CONTENT_BROWSER_ANDROID_CONTENT_VIEW_CORE_IMPL_H_