OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "webkit/plugins/webview_plugin.h" | 5 #include "webkit/plugins/webview_plugin.h" |
6 | 6 |
7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
9 #include "skia/ext/platform_canvas.h" | 9 #include "skia/ext/platform_canvas.h" |
10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" | 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" |
| 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" | 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" |
12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" | 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" | 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" |
| 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
15 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h" | 17 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h" |
16 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h" | 18 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h" |
17 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLReques
t.h" | 19 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLReques
t.h" |
18 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLRespon
se.h" | 20 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLRespon
se.h" |
19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | |
20 #include "webkit/glue/webpreferences.h" | 21 #include "webkit/glue/webpreferences.h" |
21 | 22 |
22 using WebKit::WebCanvas; | 23 using WebKit::WebCanvas; |
23 using WebKit::WebCursorInfo; | 24 using WebKit::WebCursorInfo; |
24 using WebKit::WebDragData; | 25 using WebKit::WebDragData; |
25 using WebKit::WebDragOperationsMask; | 26 using WebKit::WebDragOperationsMask; |
26 using WebKit::WebFrame; | 27 using WebKit::WebFrame; |
27 using WebKit::WebImage; | 28 using WebKit::WebImage; |
28 using WebKit::WebInputEvent; | 29 using WebKit::WebInputEvent; |
29 using WebKit::WebMouseEvent; | 30 using WebKit::WebMouseEvent; |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 | 114 |
114 NPObject* WebViewPlugin::scriptableObject() { | 115 NPObject* WebViewPlugin::scriptableObject() { |
115 return NULL; | 116 return NULL; |
116 } | 117 } |
117 | 118 |
118 bool WebViewPlugin::getFormValue(WebString& value) { | 119 bool WebViewPlugin::getFormValue(WebString& value) { |
119 return false; | 120 return false; |
120 } | 121 } |
121 | 122 |
122 void WebViewPlugin::paint(WebCanvas* canvas, const WebRect& rect) { | 123 void WebViewPlugin::paint(WebCanvas* canvas, const WebRect& rect) { |
123 gfx::Rect paintRect = gfx::IntersectRects(rect_, rect); | 124 gfx::Rect paint_rect = gfx::IntersectRects(rect_, rect); |
124 if (paintRect.IsEmpty()) | 125 if (paint_rect.IsEmpty()) |
125 return; | 126 return; |
126 | 127 |
127 paintRect.Offset(-rect_.x(), -rect_.y()); | 128 paint_rect.Offset(-rect_.x(), -rect_.y()); |
| 129 |
| 130 float content_scale = 1.0f / GetPageScaleFactor(); |
| 131 paint_rect.SetRect( |
| 132 ceil(content_scale * paint_rect.x()), |
| 133 ceil(content_scale * paint_rect.y()), |
| 134 ceil(content_scale * paint_rect.width()), |
| 135 ceil(content_scale * paint_rect.height())); |
128 | 136 |
129 canvas->translate(SkIntToScalar(rect_.x()), SkIntToScalar(rect_.y())); | 137 canvas->translate(SkIntToScalar(rect_.x()), SkIntToScalar(rect_.y())); |
130 canvas->save(); | 138 canvas->save(); |
131 | 139 |
132 web_view_->layout(); | 140 web_view_->layout(); |
133 web_view_->paint(canvas, paintRect); | 141 web_view_->paint(canvas, paint_rect); |
134 | 142 |
135 canvas->restore(); | 143 canvas->restore(); |
136 } | 144 } |
137 | 145 |
138 // Coordinates are relative to the containing window. | 146 // Coordinates are relative to the containing window. |
139 void WebViewPlugin::updateGeometry( | 147 void WebViewPlugin::updateGeometry( |
140 const WebRect& frame_rect, const WebRect& clip_rect, | 148 const WebRect& frame_rect, const WebRect& clip_rect, |
141 const WebVector<WebRect>& cut_out_rects, bool is_visible) { | 149 const WebVector<WebRect>& cut_out_rects, bool is_visible) { |
142 if (static_cast<gfx::Rect>(frame_rect) != rect_) { | 150 if (static_cast<gfx::Rect>(frame_rect) != rect_) { |
143 rect_ = frame_rect; | 151 rect_ = frame_rect; |
144 web_view_->resize(WebSize(frame_rect.width, frame_rect.height)); | 152 |
| 153 float content_scale = 1.0f / GetPageScaleFactor(); |
| 154 web_view_->resize(WebSize(content_scale * frame_rect.width, |
| 155 content_scale * frame_rect.height)); |
145 } | 156 } |
146 } | 157 } |
147 | 158 |
148 bool WebViewPlugin::acceptsInputEvents() { | 159 bool WebViewPlugin::acceptsInputEvents() { |
149 return true; | 160 return true; |
150 } | 161 } |
151 | 162 |
152 bool WebViewPlugin::handleInputEvent(const WebInputEvent& event, | 163 bool WebViewPlugin::handleInputEvent(const WebInputEvent& event, |
153 WebCursorInfo& cursor) { | 164 WebCursorInfo& cursor) { |
154 if (event.type == WebInputEvent::ContextMenu) { | 165 if (event.type == WebInputEvent::ContextMenu) { |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 error.unreachableURL = request.url(); | 243 error.unreachableURL = request.url(); |
233 return error; | 244 return error; |
234 } | 245 } |
235 | 246 |
236 void WebViewPlugin::didReceiveResponse(WebFrame* frame, | 247 void WebViewPlugin::didReceiveResponse(WebFrame* frame, |
237 unsigned identifier, | 248 unsigned identifier, |
238 const WebURLResponse& response) { | 249 const WebURLResponse& response) { |
239 WebFrameClient::didReceiveResponse(frame, identifier, response); | 250 WebFrameClient::didReceiveResponse(frame, identifier, response); |
240 } | 251 } |
241 | 252 |
| 253 float WebViewPlugin::GetPageScaleFactor() { |
| 254 if (container_) { |
| 255 WebFrame* frame = container_->element().document().frame(); |
| 256 WebView* top_view = frame->top()->view(); |
| 257 return top_view->pageScaleFactor(); |
| 258 } |
| 259 return 1.0f; |
| 260 } |
| 261 |
242 } // namespace webkit | 262 } // namespace webkit |
OLD | NEW |