OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "mojo/services/html_viewer/html_document_view.h" | 5 #include "mojo/services/html_viewer/html_document_view.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
11 #include "base/thread_task_runner_handle.h" | 11 #include "base/thread_task_runner_handle.h" |
12 #include "mojo/public/cpp/system/data_pipe.h" | 12 #include "mojo/public/cpp/system/data_pipe.h" |
13 #include "mojo/services/html_viewer/blink_input_events_type_converters.h" | 13 #include "mojo/services/html_viewer/blink_input_events_type_converters.h" |
14 #include "mojo/services/html_viewer/webstoragenamespace_impl.h" | 14 #include "mojo/services/html_viewer/webstoragenamespace_impl.h" |
15 #include "mojo/services/html_viewer/weburlloader_impl.h" | 15 #include "mojo/services/html_viewer/weburlloader_impl.h" |
16 #include "mojo/services/public/cpp/view_manager/node.h" | 16 #include "mojo/services/public/cpp/view_manager/view.h" |
17 #include "skia/ext/refptr.h" | 17 #include "skia/ext/refptr.h" |
18 #include "third_party/WebKit/public/platform/Platform.h" | 18 #include "third_party/WebKit/public/platform/Platform.h" |
19 #include "third_party/WebKit/public/platform/WebHTTPHeaderVisitor.h" | 19 #include "third_party/WebKit/public/platform/WebHTTPHeaderVisitor.h" |
20 #include "third_party/WebKit/public/web/WebConsoleMessage.h" | 20 #include "third_party/WebKit/public/web/WebConsoleMessage.h" |
21 #include "third_party/WebKit/public/web/WebDocument.h" | 21 #include "third_party/WebKit/public/web/WebDocument.h" |
22 #include "third_party/WebKit/public/web/WebElement.h" | 22 #include "third_party/WebKit/public/web/WebElement.h" |
23 #include "third_party/WebKit/public/web/WebInputEvent.h" | 23 #include "third_party/WebKit/public/web/WebInputEvent.h" |
24 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 24 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
25 #include "third_party/WebKit/public/web/WebScriptSource.h" | 25 #include "third_party/WebKit/public/web/WebScriptSource.h" |
26 #include "third_party/WebKit/public/web/WebSettings.h" | 26 #include "third_party/WebKit/public/web/WebSettings.h" |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 weak_factory_(this) { | 164 weak_factory_(this) { |
165 } | 165 } |
166 | 166 |
167 HTMLDocumentView::~HTMLDocumentView() { | 167 HTMLDocumentView::~HTMLDocumentView() { |
168 if (web_view_) | 168 if (web_view_) |
169 web_view_->close(); | 169 web_view_->close(); |
170 if (root_) | 170 if (root_) |
171 root_->RemoveObserver(this); | 171 root_->RemoveObserver(this); |
172 } | 172 } |
173 | 173 |
174 void HTMLDocumentView::AttachToNode(Node* node) { | 174 void HTMLDocumentView::AttachToView(View* view) { |
175 root_ = node; | 175 root_ = view; |
176 root_->SetColor(SK_ColorCYAN); // Dummy background color. | 176 root_->SetColor(SK_ColorCYAN); // Dummy background color. |
177 | 177 |
178 web_view_ = blink::WebView::create(this); | 178 web_view_ = blink::WebView::create(this); |
179 ConfigureSettings(web_view_->settings()); | 179 ConfigureSettings(web_view_->settings()); |
180 web_view_->setMainFrame(blink::WebLocalFrame::create(this)); | 180 web_view_->setMainFrame(blink::WebLocalFrame::create(this)); |
181 web_view_->resize(root_->bounds().size()); | 181 web_view_->resize(root_->bounds().size()); |
182 | 182 |
183 root_->AddObserver(this); | 183 root_->AddObserver(this); |
184 } | 184 } |
185 | 185 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 const blink::WebString& stack_trace) { | 259 const blink::WebString& stack_trace) { |
260 } | 260 } |
261 | 261 |
262 void HTMLDocumentView::didNavigateWithinPage( | 262 void HTMLDocumentView::didNavigateWithinPage( |
263 blink::WebLocalFrame* frame, const blink::WebHistoryItem& history_item, | 263 blink::WebLocalFrame* frame, const blink::WebHistoryItem& history_item, |
264 blink::WebHistoryCommitType commit_type) { | 264 blink::WebHistoryCommitType commit_type) { |
265 navigator_host_->DidNavigateLocally(root_->id(), | 265 navigator_host_->DidNavigateLocally(root_->id(), |
266 history_item.urlString().utf8()); | 266 history_item.urlString().utf8()); |
267 } | 267 } |
268 | 268 |
269 void HTMLDocumentView::OnNodeBoundsChanged(Node* node, | 269 void HTMLDocumentView::OnViewBoundsChanged(View* view, |
270 const gfx::Rect& old_bounds, | 270 const gfx::Rect& old_bounds, |
271 const gfx::Rect& new_bounds) { | 271 const gfx::Rect& new_bounds) { |
272 DCHECK_EQ(node, root_); | 272 DCHECK_EQ(view, root_); |
273 web_view_->resize(node->bounds().size()); | 273 web_view_->resize(view->bounds().size()); |
274 } | 274 } |
275 | 275 |
276 void HTMLDocumentView::OnNodeDestroyed(Node* node) { | 276 void HTMLDocumentView::OnViewDestroyed(View* view) { |
277 DCHECK_EQ(node, root_); | 277 DCHECK_EQ(view, root_); |
278 node->RemoveObserver(this); | 278 view->RemoveObserver(this); |
279 root_ = NULL; | 279 root_ = NULL; |
280 } | 280 } |
281 | 281 |
282 void HTMLDocumentView::OnNodeInputEvent(Node* node, const EventPtr& event) { | 282 void HTMLDocumentView::OnViewInputEvent(View* view, const EventPtr& event) { |
283 scoped_ptr<blink::WebInputEvent> web_event = | 283 scoped_ptr<blink::WebInputEvent> web_event = |
284 TypeConverter<EventPtr, scoped_ptr<blink::WebInputEvent> >::ConvertTo( | 284 TypeConverter<EventPtr, scoped_ptr<blink::WebInputEvent> >::ConvertTo( |
285 event); | 285 event); |
286 if (web_event) | 286 if (web_event) |
287 web_view_->handleInputEvent(*web_event); | 287 web_view_->handleInputEvent(*web_event); |
288 } | 288 } |
289 | 289 |
290 void HTMLDocumentView::Repaint() { | 290 void HTMLDocumentView::Repaint() { |
291 repaint_pending_ = false; | 291 repaint_pending_ = false; |
292 | 292 |
293 web_view_->animate(0.0); | 293 web_view_->animate(0.0); |
294 web_view_->layout(); | 294 web_view_->layout(); |
295 | 295 |
296 int width = web_view_->size().width; | 296 int width = web_view_->size().width; |
297 int height = web_view_->size().height; | 297 int height = web_view_->size().height; |
298 | 298 |
299 skia::RefPtr<SkCanvas> canvas = skia::AdoptRef(SkCanvas::NewRaster( | 299 skia::RefPtr<SkCanvas> canvas = skia::AdoptRef(SkCanvas::NewRaster( |
300 SkImageInfo::MakeN32(width, height, kOpaque_SkAlphaType))); | 300 SkImageInfo::MakeN32(width, height, kOpaque_SkAlphaType))); |
301 | 301 |
302 web_view_->paint(canvas.get(), gfx::Rect(0, 0, width, height)); | 302 web_view_->paint(canvas.get(), gfx::Rect(0, 0, width, height)); |
303 | 303 |
304 root_->SetContents(canvas->getDevice()->accessBitmap(false)); | 304 root_->SetContents(canvas->getDevice()->accessBitmap(false)); |
305 } | 305 } |
306 | 306 |
307 } // namespace mojo | 307 } // namespace mojo |
OLD | NEW |