Allow only one bookmark to be added for multiple fast starring
[chromium-blink-merge.git] / components / view_manager / display_manager.h
blob6b1fe127990b1c05371a0b9eb109c05971989a39
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
3 // found in the LICENSE file.
5 #ifndef COMPONENTS_VIEW_MANAGER_DISPLAY_MANAGER_H_
6 #define COMPONENTS_VIEW_MANAGER_DISPLAY_MANAGER_H_
8 #include <map>
10 #include "base/basictypes.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/weak_ptr.h"
13 #include "base/timer/timer.h"
14 #include "components/view_manager/display_manager_delegate.h"
15 #include "components/view_manager/public/interfaces/display.mojom.h"
16 #include "components/view_manager/public/interfaces/view_manager.mojom.h"
17 #include "third_party/mojo/src/mojo/public/cpp/bindings/callback.h"
18 #include "ui/gfx/geometry/rect.h"
19 #include "ui/platform_window/platform_window_delegate.h"
21 namespace cc {
22 class SurfaceIdAllocator;
23 } // namespace cc
25 namespace gles2 {
26 class GpuState;
27 } // namespace gles2
29 namespace native_viewport {
30 class OnscreenContextProvider;
31 } // namespace native_viewport
33 namespace mojo {
34 class ApplicationImpl;
35 } // namespace mojo
37 namespace ui {
38 class PlatformWindow;
39 struct TextInputState;
42 namespace view_manager {
44 class DisplayManagerFactory;
45 class EventDispatcher;
46 class ServerView;
48 // DisplayManager is used to connect the root ServerView to a display.
49 class DisplayManager {
50 public:
51 virtual ~DisplayManager() {}
53 static DisplayManager* Create(
54 bool is_headless,
55 mojo::ApplicationImpl* app_impl,
56 const scoped_refptr<gles2::GpuState>& gpu_state);
58 virtual void Init(DisplayManagerDelegate* delegate) = 0;
60 // Schedules a paint for the specified region in the coordinates of |view|.
61 virtual void SchedulePaint(const ServerView* view,
62 const gfx::Rect& bounds) = 0;
64 virtual void SetViewportSize(const gfx::Size& size) = 0;
66 virtual const mojo::ViewportMetrics& GetViewportMetrics() = 0;
68 virtual void UpdateTextInputState(const ui::TextInputState& state) = 0;
69 virtual void SetImeVisibility(bool visible) = 0;
71 // Overrides factory for testing. Default (NULL) value indicates regular
72 // (non-test) environment.
73 static void set_factory_for_testing(DisplayManagerFactory* factory) {
74 DisplayManager::factory_ = factory;
77 private:
78 // Static factory instance (always NULL for non-test).
79 static DisplayManagerFactory* factory_;
82 // DisplayManager implementation that connects to the services necessary to
83 // actually display.
84 class DefaultDisplayManager :
85 public DisplayManager,
86 public ui::PlatformWindowDelegate {
87 public:
88 DefaultDisplayManager(bool is_headless,
89 mojo::ApplicationImpl* app_impl,
90 const scoped_refptr<gles2::GpuState>& gpu_state);
91 ~DefaultDisplayManager() override;
93 // DisplayManager:
94 void Init(DisplayManagerDelegate* delegate) override;
95 void SchedulePaint(const ServerView* view, const gfx::Rect& bounds) override;
96 void SetViewportSize(const gfx::Size& size) override;
97 const mojo::ViewportMetrics& GetViewportMetrics() override;
98 void UpdateTextInputState(const ui::TextInputState& state) override;
99 void SetImeVisibility(bool visible) override;
101 private:
102 void WantToDraw();
103 void Draw();
104 void DidDraw();
105 void UpdateMetrics(const gfx::Size& size, float device_pixel_ratio);
107 // ui::PlatformWindowDelegate:
108 void OnBoundsChanged(const gfx::Rect& new_bounds) override;
109 void OnDamageRect(const gfx::Rect& damaged_region) override;
110 void DispatchEvent(ui::Event* event) override;
111 void OnCloseRequest() override;
112 void OnClosed() override;
113 void OnWindowStateChanged(ui::PlatformWindowState new_state) override;
114 void OnLostCapture() override;
115 void OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget,
116 float device_pixel_ratio) override;
117 void OnActivationChanged(bool active) override;
119 bool is_headless_;
120 mojo::ApplicationImpl* app_impl_;
121 scoped_refptr<gles2::GpuState> gpu_state_;
122 DisplayManagerDelegate* delegate_;
124 mojo::ViewportMetrics metrics_;
125 gfx::Rect dirty_rect_;
126 base::Timer draw_timer_;
127 bool frame_pending_;
129 mojo::DisplayPtr display_;
130 scoped_ptr<native_viewport::OnscreenContextProvider> context_provider_;
131 scoped_ptr<ui::PlatformWindow> platform_window_;
133 base::WeakPtrFactory<DefaultDisplayManager> weak_factory_;
135 DISALLOW_COPY_AND_ASSIGN(DefaultDisplayManager);
138 } // namespace view_manager
140 #endif // COMPONENTS_VIEW_MANAGER_DISPLAY_MANAGER_H_