OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "sky/shell/ui/engine.h" | 5 #include "sky/shell/ui/engine.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "sky/engine/public/platform/WebInputEvent.h" | 8 #include "sky/engine/public/platform/WebInputEvent.h" |
9 #include "sky/engine/public/web/Sky.h" | 9 #include "sky/engine/public/web/Sky.h" |
10 #include "sky/engine/public/web/WebLocalFrame.h" | 10 #include "sky/engine/public/web/WebLocalFrame.h" |
(...skipping 21 matching lines...) Expand all Loading... | |
32 } | 32 } |
33 | 33 |
34 base::WeakPtr<Engine> Engine::GetWeakPtr() { | 34 base::WeakPtr<Engine> Engine::GetWeakPtr() { |
35 return weak_factory_.GetWeakPtr(); | 35 return weak_factory_.GetWeakPtr(); |
36 } | 36 } |
37 | 37 |
38 void Engine::Init(mojo::ScopedMessagePipeHandle service_provider) { | 38 void Engine::Init(mojo::ScopedMessagePipeHandle service_provider) { |
39 platform_impl_.reset(new PlatformImpl( | 39 platform_impl_.reset(new PlatformImpl( |
40 mojo::MakeProxy<mojo::ServiceProvider>(service_provider.Pass()))); | 40 mojo::MakeProxy<mojo::ServiceProvider>(service_provider.Pass()))); |
41 blink::initialize(platform_impl_.get()); | 41 blink::initialize(platform_impl_.get()); |
42 | |
43 web_view_ = blink::WebView::create(this); | |
44 web_view_->setMainFrame(blink::WebLocalFrame::create(this)); | |
45 web_view_->mainFrame()->load( | |
46 GURL("http://domokit.github.io/sky/examples/spinning-square.sky")); | |
47 } | 42 } |
48 | 43 |
49 void Engine::BeginFrame(base::TimeTicks frame_time) { | 44 void Engine::BeginFrame(base::TimeTicks frame_time) { |
50 double frame_time_sec = (frame_time - base::TimeTicks()).InSecondsF(); | 45 double frame_time_sec = (frame_time - base::TimeTicks()).InSecondsF(); |
51 double deadline_sec = frame_time_sec; | 46 double deadline_sec = frame_time_sec; |
52 double interval_sec = 1.0 / 60; | 47 double interval_sec = 1.0 / 60; |
53 blink::WebBeginFrameArgs args(frame_time_sec, deadline_sec, interval_sec); | 48 blink::WebBeginFrameArgs args(frame_time_sec, deadline_sec, interval_sec); |
54 | 49 |
55 web_view_->beginFrame(args); | 50 web_view_->beginFrame(args); |
56 web_view_->layout(); | 51 web_view_->layout(); |
(...skipping 12 matching lines...) Expand all Loading... | |
69 | 64 |
70 void Engine::ConnectToViewportObserver( | 65 void Engine::ConnectToViewportObserver( |
71 mojo::InterfaceRequest<ViewportObserver> request) { | 66 mojo::InterfaceRequest<ViewportObserver> request) { |
72 viewport_observer_binding_.Bind(request.Pass()); | 67 viewport_observer_binding_.Bind(request.Pass()); |
73 } | 68 } |
74 | 69 |
75 void Engine::OnViewportMetricsChanged(int width, int height, | 70 void Engine::OnViewportMetricsChanged(int width, int height, |
76 float device_pixel_ratio) { | 71 float device_pixel_ratio) { |
77 physical_size_.SetSize(width, height); | 72 physical_size_.SetSize(width, height); |
78 device_pixel_ratio_ = device_pixel_ratio; | 73 device_pixel_ratio_ = device_pixel_ratio; |
79 web_view_->setDeviceScaleFactor(device_pixel_ratio); | 74 if (web_view_) |
80 gfx::SizeF size = gfx::ScaleSize(physical_size_, 1 / device_pixel_ratio); | 75 UpdateWebViewSize(); |
76 } | |
77 | |
78 void Engine::UpdateWebViewSize() | |
79 { | |
abarth-chromium
2015/02/20 22:10:49
Chromium style is to combine these lines.
| |
80 CHECK(web_view_); | |
abarth-chromium
2015/02/20 22:10:49
CHECK -> DCHECK
| |
81 web_view_->setDeviceScaleFactor(device_pixel_ratio_); | |
82 gfx::SizeF size = gfx::ScaleSize(physical_size_, 1 / device_pixel_ratio_); | |
81 // FIXME: We should be able to set the size of the WebView in floating point | 83 // FIXME: We should be able to set the size of the WebView in floating point |
82 // because its in logical pixels. | 84 // because its in logical pixels. |
83 web_view_->resize(blink::WebSize(size.width(), size.height())); | 85 web_view_->resize(blink::WebSize(size.width(), size.height())); |
84 } | 86 } |
85 | 87 |
86 void Engine::OnInputEvent(InputEventPtr event) { | 88 void Engine::OnInputEvent(InputEventPtr event) { |
87 scoped_ptr<blink::WebInputEvent> web_event = | 89 scoped_ptr<blink::WebInputEvent> web_event = |
88 ConvertEvent(event, device_pixel_ratio_); | 90 ConvertEvent(event, device_pixel_ratio_); |
89 if (!web_event) | 91 if (!web_event) |
90 return; | 92 return; |
91 web_view_->handleInputEvent(*web_event); | 93 web_view_->handleInputEvent(*web_event); |
92 } | 94 } |
93 | 95 |
96 void Engine::LoadURL(const mojo::String& url) { | |
97 web_view_ = blink::WebView::create(this); | |
98 web_view_->setMainFrame(blink::WebLocalFrame::create(this)); | |
99 UpdateWebViewSize(); | |
100 web_view_->mainFrame()->load(GURL(url)); | |
101 } | |
102 | |
94 void Engine::initializeLayerTreeView() { | 103 void Engine::initializeLayerTreeView() { |
95 } | 104 } |
96 | 105 |
97 void Engine::scheduleVisualUpdate() { | 106 void Engine::scheduleVisualUpdate() { |
98 animator_->RequestFrame(); | 107 animator_->RequestFrame(); |
99 } | 108 } |
100 | 109 |
101 } // namespace shell | 110 } // namespace shell |
102 } // namespace sky | 111 } // namespace sky |
OLD | NEW |