[android_webview] Use a fraction to calculate scroll offset.
[chromium-blink-merge.git] / android_webview / browser / browser_view_renderer.h
blob0ae9538484cbafb764625d40288befcba32dc1ca
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
3 // found in the LICENSE file.
5 #ifndef ANDROID_WEBVIEW_BROWSER_BROWSER_VIEW_RENDERER_H_
6 #define ANDROID_WEBVIEW_BROWSER_BROWSER_VIEW_RENDERER_H_
8 #include "base/android/scoped_java_ref.h"
9 #include "skia/ext/refptr.h"
10 #include "ui/gfx/point.h"
11 #include "ui/gfx/rect.h"
12 #include "ui/gfx/vector2d_f.h"
14 class SkPicture;
15 struct AwDrawGLInfo;
16 struct AwDrawSWFunctionTable;
18 namespace content {
19 class ContentViewCore;
22 namespace android_webview {
24 // Interface for all the WebView-specific content rendering operations.
25 // Provides software and hardware rendering and the Capture Picture API.
26 class BrowserViewRenderer {
27 public:
28 class Client {
29 public:
30 // Request DrawGL be called. Passing null canvas implies the request
31 // will be of AwDrawGLInfo::kModeProcess type. The callback
32 // may never be made, and the mode may be promoted to kModeDraw.
33 virtual bool RequestDrawGL(jobject canvas) = 0;
35 // Called when a new Picture is available. Needs to be enabled
36 // via the EnableOnNewPicture method.
37 virtual void OnNewPicture() = 0;
39 // Called to trigger view invalidations.
40 virtual void PostInvalidate() = 0;
42 // Synchronously call back to SetGlobalVisibleRect with current value.
43 virtual void UpdateGlobalVisibleRect() = 0;
45 // Called to get view's absolute location on the screen.
46 virtual gfx::Point GetLocationOnScreen() = 0;
48 // Try to set the view's scroll offset to |new_value|.
49 virtual void ScrollContainerViewTo(gfx::Vector2d new_value) = 0;
51 // Set the view's scroll offset cap to |new_value|.
52 virtual void SetMaxContainerViewScrollOffset(gfx::Vector2d new_value) = 0;
54 // Set the current page scale to |page_scale_factor|.
55 virtual void SetPageScaleFactor(float page_scale_factor) = 0;
57 // Set the current contents_size to |contents_size_dip|.
58 virtual void SetContentsSize(gfx::SizeF contents_size_dip) = 0;
60 // Handle overscroll.
61 virtual void DidOverscroll(gfx::Vector2d overscroll_delta) = 0;
63 protected:
64 virtual ~Client() {}
67 // Delegate to perform rendering actions involving Java objects.
68 class JavaHelper {
69 public:
70 // Creates a RGBA_8888 Java Bitmap object of the requested size.
71 virtual base::android::ScopedJavaLocalRef<jobject> CreateBitmap(
72 JNIEnv* env,
73 int width,
74 int height,
75 const base::android::JavaRef<jobject>& jcanvas,
76 void* owner_key) = 0;
78 // Draws the provided Java Bitmap into the provided Java Canvas.
79 virtual void DrawBitmapIntoCanvas(
80 JNIEnv* env,
81 const base::android::JavaRef<jobject>& jbitmap,
82 const base::android::JavaRef<jobject>& jcanvas,
83 int x,
84 int y) = 0;
86 // Creates a Java Picture object that records drawing the provided Bitmap.
87 virtual base::android::ScopedJavaLocalRef<jobject> RecordBitmapIntoPicture(
88 JNIEnv* env,
89 const base::android::JavaRef<jobject>& jbitmap) = 0;
91 protected:
92 virtual ~JavaHelper() {}
95 // Global hookup methods.
96 static void SetAwDrawSWFunctionTable(AwDrawSWFunctionTable* table);
97 static AwDrawSWFunctionTable* GetAwDrawSWFunctionTable();
99 // Rendering methods.
101 // Main handler for view drawing: performs a SW draw immediately, or sets up
102 // a subsequent GL Draw (via Client::RequestDrawGL) and returns true. A false
103 // return value indicates nothing was or will be drawn.
104 // |java_canvas| is the target of the draw. |is_hardware_canvas| indicates
105 // a GL Draw maybe possible on this canvas. |scroll| if the view's current
106 // scroll offset. |clip| is the canvas's clip bounds. |visible_rect| is the
107 // intersection of the view size and the window in window coordinates.
108 virtual bool OnDraw(jobject java_canvas,
109 bool is_hardware_canvas,
110 const gfx::Vector2d& scroll,
111 const gfx::Rect& clip) = 0;
113 // Called in response to a prior Client::RequestDrawGL() call. See
114 // AwDrawGLInfo documentation for more details of the contract.
115 virtual void DrawGL(AwDrawGLInfo* draw_info) = 0;
117 // The global visible rect changed and this is the new value.
118 virtual void SetGlobalVisibleRect(const gfx::Rect& visible_rect) = 0;
120 // CapturePicture API methods.
121 virtual skia::RefPtr<SkPicture> CapturePicture(int width, int height) = 0;
122 virtual void EnableOnNewPicture(bool enabled) = 0;
124 // View update notifications.
125 virtual void SetIsPaused(bool paused) = 0;
126 virtual void SetViewVisibility(bool visible) = 0;
127 virtual void SetWindowVisibility(bool visible) = 0;
128 virtual void OnSizeChanged(int width, int height) = 0;
129 virtual void OnAttachedToWindow(int width, int height) = 0;
130 virtual void OnDetachedFromWindow() = 0;
132 // Sets the scale for logical<->physical pixel conversions.
133 virtual void SetDipScale(float dip_scale) = 0;
135 // Set the root layer scroll offset to |new_value|.
136 virtual void ScrollTo(gfx::Vector2d new_value) = 0;
138 // Android views hierarchy gluing.
139 virtual bool IsAttachedToWindow() = 0;
140 virtual bool IsVisible() = 0;
141 virtual gfx::Rect GetScreenRect() = 0;
143 virtual ~BrowserViewRenderer() {}
146 } // namespace android_webview
148 #endif // ANDROID_WEBVIEW_BROWSER_BROWSER_VIEW_RENDERER_H_