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/WebElement.h" | 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" |
12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.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" |
15 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h" | 16 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h" |
16 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h" | 17 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h" |
17 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLReques t.h" | 18 #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" | 19 #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 "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
20 #include "webkit/glue/webpreferences.h" | 21 #include "webkit/glue/webpreferences.h" |
21 | 22 |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 paintRect = gfx::IntersectRects(rect_, rect); |
124 if (paintRect.IsEmpty()) | 125 if (paintRect.IsEmpty()) |
125 return; | 126 return; |
126 | 127 |
127 paintRect.Offset(-rect_.x(), -rect_.y()); | 128 paintRect.Offset(-rect_.x(), -rect_.y()); |
128 | 129 |
130 float pageScaleFactor = 1.0f; | |
jam
2012/11/14 20:59:55
nit: google style is page_scale_factor. if you can
qinmin
2012/11/14 22:16:59
Done.
| |
131 if (container_) { | |
132 pageScaleFactor = container_->element().document().frame()->top()->view() | |
133 ->pageScaleFactor(); | |
Bernhard Bauer
2012/11/14 21:12:00
Urgh. Could you extract something in here to a loc
qinmin
2012/11/14 22:16:59
Done.
| |
134 } | |
135 float content_scale = 1.0f / pageScaleFactor; | |
136 paintRect.SetRect( | |
137 ceil(static_cast<float>(content_scale * paintRect.x())), | |
Bernhard Bauer
2012/11/14 21:12:00
Why do we need the static_cast here? Shouldn't flo
qinmin
2012/11/14 22:16:59
removed.
| |
138 ceil(static_cast<float>(content_scale * paintRect.y())), | |
139 ceil(static_cast<float>(content_scale * paintRect.width())), | |
140 ceil(static_cast<float>(content_scale * paintRect.height()))); | |
141 | |
129 canvas->translate(SkIntToScalar(rect_.x()), SkIntToScalar(rect_.y())); | 142 canvas->translate(SkIntToScalar(rect_.x()), SkIntToScalar(rect_.y())); |
130 canvas->save(); | 143 canvas->save(); |
131 | 144 |
132 web_view_->layout(); | 145 web_view_->layout(); |
133 web_view_->paint(canvas, paintRect); | 146 web_view_->paint(canvas, paintRect); |
134 | 147 |
135 canvas->restore(); | 148 canvas->restore(); |
136 } | 149 } |
137 | 150 |
138 // Coordinates are relative to the containing window. | 151 // Coordinates are relative to the containing window. |
139 void WebViewPlugin::updateGeometry( | 152 void WebViewPlugin::updateGeometry( |
140 const WebRect& frame_rect, const WebRect& clip_rect, | 153 const WebRect& frame_rect, const WebRect& clip_rect, |
141 const WebVector<WebRect>& cut_out_rects, bool is_visible) { | 154 const WebVector<WebRect>& cut_out_rects, bool is_visible) { |
142 if (static_cast<gfx::Rect>(frame_rect) != rect_) { | 155 if (static_cast<gfx::Rect>(frame_rect) != rect_) { |
143 rect_ = frame_rect; | 156 rect_ = frame_rect; |
144 web_view_->resize(WebSize(frame_rect.width, frame_rect.height)); | 157 |
158 float pageScaleFactor = 1.0f; | |
159 if (container_) { | |
160 pageScaleFactor = container_->element().document().frame()->top()-> | |
161 view()->pageScaleFactor(); | |
Bernhard Bauer
2012/11/14 21:12:00
Same "urgh" here. Maybe you could (also) pull it o
qinmin
2012/11/14 22:16:59
Done. added a GetPageScaleFactor() method
| |
162 } | |
163 float content_scale = 1.0f / pageScaleFactor; | |
164 | |
165 web_view_->resize(WebSize(content_scale * frame_rect.width, | |
166 content_scale * frame_rect.height)); | |
145 } | 167 } |
146 } | 168 } |
147 | 169 |
148 bool WebViewPlugin::acceptsInputEvents() { | 170 bool WebViewPlugin::acceptsInputEvents() { |
149 return true; | 171 return true; |
150 } | 172 } |
151 | 173 |
152 bool WebViewPlugin::handleInputEvent(const WebInputEvent& event, | 174 bool WebViewPlugin::handleInputEvent(const WebInputEvent& event, |
153 WebCursorInfo& cursor) { | 175 WebCursorInfo& cursor) { |
154 if (event.type == WebInputEvent::ContextMenu) { | 176 if (event.type == WebInputEvent::ContextMenu) { |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
233 return error; | 255 return error; |
234 } | 256 } |
235 | 257 |
236 void WebViewPlugin::didReceiveResponse(WebFrame* frame, | 258 void WebViewPlugin::didReceiveResponse(WebFrame* frame, |
237 unsigned identifier, | 259 unsigned identifier, |
238 const WebURLResponse& response) { | 260 const WebURLResponse& response) { |
239 WebFrameClient::didReceiveResponse(frame, identifier, response); | 261 WebFrameClient::didReceiveResponse(frame, identifier, response); |
240 } | 262 } |
241 | 263 |
242 } // namespace webkit | 264 } // namespace webkit |
OLD | NEW |