Vectorize website settings icons in omnibox
[chromium-blink-merge.git] / components / view_manager / view_tree_host_impl.cc
blob1490e1edb6b2cec3be5528470a533b633f1d8bd7
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
3 // found in the LICENSE file.
5 #include "components/view_manager/view_tree_host_impl.h"
7 #include "components/view_manager/connection_manager.h"
8 #include "components/view_manager/display_manager.h"
9 #include "components/view_manager/public/cpp/types.h"
10 #include "components/view_manager/view_tree_host_delegate.h"
11 #include "mojo/converters/geometry/geometry_type_converters.h"
13 namespace view_manager {
15 ViewTreeHostImpl::ViewTreeHostImpl(
16 mojo::ViewTreeHostClientPtr client,
17 ConnectionManager* connection_manager,
18 bool is_headless,
19 mojo::ApplicationImpl* app_impl,
20 const scoped_refptr<gles2::GpuState>& gpu_state,
21 const scoped_refptr<surfaces::SurfacesState>& surfaces_state)
22 : delegate_(nullptr),
23 connection_manager_(connection_manager),
24 client_(client.Pass()),
25 display_manager_(
26 DisplayManager::Create(is_headless,
27 app_impl,
28 gpu_state,
29 surfaces_state)) {
30 display_manager_->Init(this);
33 ViewTreeHostImpl::~ViewTreeHostImpl() {
36 void ViewTreeHostImpl::Init(ViewTreeHostDelegate* delegate) {
37 delegate_ = delegate;
38 if (delegate_ && root_)
39 delegate_->OnDisplayInitialized();
42 ViewTreeImpl* ViewTreeHostImpl::GetViewTree() {
43 return delegate_ ? delegate_->GetViewTree() : nullptr;
46 bool ViewTreeHostImpl::IsViewAttachedToRoot(const ServerView* view) const {
47 return root_->Contains(view) && view != root_.get();
50 bool ViewTreeHostImpl::SchedulePaintIfInViewport(const ServerView* view,
51 const gfx::Rect& bounds) {
52 if (root_->Contains(view)) {
53 display_manager_->SchedulePaint(view, bounds);
54 return true;
56 return false;
59 const mojo::ViewportMetrics& ViewTreeHostImpl::GetViewportMetrics() const {
60 return display_manager_->GetViewportMetrics();
63 void ViewTreeHostImpl::UpdateTextInputState(const ui::TextInputState& state) {
64 display_manager_->UpdateTextInputState(state);
67 void ViewTreeHostImpl::SetImeVisibility(bool visible) {
68 display_manager_->SetImeVisibility(visible);
71 void ViewTreeHostImpl::SetSize(mojo::SizePtr size) {
72 display_manager_->SetViewportSize(size.To<gfx::Size>());
75 void ViewTreeHostImpl::AddAccelerator(uint32_t id,
76 mojo::KeyboardCode keyboard_code,
77 mojo::EventFlags flags) {
78 connection_manager_->AddAccelerator(this, id, keyboard_code, flags);
81 void ViewTreeHostImpl::RemoveAccelerator(uint32_t id) {
82 connection_manager_->RemoveAccelerator(this, id);
85 ServerView* ViewTreeHostImpl::GetRootView() {
86 return root_.get();
89 void ViewTreeHostImpl::OnEvent(mojo::EventPtr event) {
90 connection_manager_->OnEvent(this, event.Pass());
93 void ViewTreeHostImpl::OnDisplayClosed() {
94 if (delegate_)
95 delegate_->OnDisplayClosed();
98 void ViewTreeHostImpl::OnViewportMetricsChanged(
99 const mojo::ViewportMetrics& old_metrics,
100 const mojo::ViewportMetrics& new_metrics) {
101 if (!root_) {
102 root_.reset(connection_manager_->CreateServerView(
103 RootViewId(connection_manager_->GetAndAdvanceNextHostId())));
104 root_->SetBounds(gfx::Rect(new_metrics.size_in_pixels.To<gfx::Size>()));
105 root_->SetVisible(true);
106 if (delegate_)
107 delegate_->OnDisplayInitialized();
108 } else {
109 root_->SetBounds(gfx::Rect(new_metrics.size_in_pixels.To<gfx::Size>()));
111 // TODO(fsamuel): We shouldn't broadcast this to all connections but only
112 // those within a window root.
113 connection_manager_->ProcessViewportMetricsChanged(old_metrics, new_metrics);
116 } // namespace view_manager