OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef UI_OZONE_PLATFORM_CACA_CACA_WINDOW_H_ | |
6 #define UI_OZONE_PLATFORM_CACA_CACA_WINDOW_H_ | |
7 | |
8 #include <caca.h> | |
9 #include <stdint.h> | |
10 | |
11 #include "base/debug/stack_trace.h" | |
12 #include "base/macros.h" | |
13 #include "base/memory/weak_ptr.h" | |
14 #include "ui/events/platform/platform_event_dispatcher.h" | |
15 #include "ui/gfx/geometry/size.h" | |
16 #include "ui/gfx/native_widget_types.h" | |
17 #include "ui/ozone/platform/caca/scoped_caca_types.h" | |
18 #include "ui/platform_window/platform_window.h" | |
19 | |
20 namespace ui { | |
21 | |
22 class CacaEventSource; | |
23 class CacaWindowManager; | |
24 class PlatformWindowDelegate; | |
25 | |
26 // Basic initialization of Libcaca. This needs to be shared between SFO and EFO | |
27 // since both need the |display_| to draw and process events respectively. | |
28 // Note, |canvas_| needs to be here since it is needed for creating a | |
29 // |display_|. | |
30 class CacaWindow : public PlatformWindow, public PlatformEventDispatcher { | |
31 public: | |
32 CacaWindow(PlatformWindowDelegate* delegate, | |
33 CacaWindowManager* manager, | |
34 CacaEventSource* event_source, | |
35 const gfx::Rect& bounds); | |
36 ~CacaWindow() override; | |
37 | |
38 bool Initialize(); | |
39 | |
40 // Handlers for events received from libcaca. | |
41 void OnCacaQuit(); | |
42 void OnCacaResize(); | |
43 void OnCacaEvent(ui::Event* event); | |
44 | |
45 // This is the Caca canvas size. | |
46 gfx::Size physical_size() const { return physical_size_; } | |
47 gfx::Size bitmap_size() const { return bitmap_size_; } | |
48 caca_display_t* display() const { return display_.get(); } | |
49 | |
50 // PlatformWindow: | |
51 gfx::Rect GetBounds() override; | |
52 void SetBounds(const gfx::Rect& bounds) override; | |
53 void Show() override; | |
54 void Hide() override; | |
55 void Close() override; | |
56 void SetCapture() override; | |
57 void ReleaseCapture() override; | |
58 void ToggleFullscreen() override; | |
59 void Maximize() override; | |
60 void Minimize() override; | |
61 void Restore() override; | |
62 void SetCursor(PlatformCursor cursor) override; | |
63 void MoveCursorTo(const gfx::Point& location) override; | |
64 void ConfineCursorToBounds(const gfx::Rect& bounds) override; | |
65 PlatformImeController* GetPlatformImeController() override; | |
66 void SetTitle(const base::string16& title) override; | |
67 | |
68 // PlatformEventDispatcher: | |
69 bool CanDispatchEvent(const PlatformEvent& event) override; | |
70 uint32_t DispatchEvent(const PlatformEvent& event) override; | |
71 | |
72 private: | |
73 // Event polling. | |
74 void TryProcessingEvent(); | |
75 | |
76 // Sync sizes with libcaca. | |
77 void UpdateDisplaySize(); | |
78 | |
79 PlatformWindowDelegate* delegate_; | |
80 CacaWindowManager* manager_; | |
81 CacaEventSource* event_source_; | |
82 gfx::AcceleratedWidget widget_; | |
83 | |
84 ScopedCacaCanvas canvas_; | |
85 ScopedCacaDisplay display_; | |
86 | |
87 // Size of the console in characters. This can be changed by setting | |
88 // CACA_GEOMETRY environment variable. | |
89 gfx::Size physical_size_; | |
90 | |
91 // Size of the backing buffer we draw into. Size in pixels. | |
92 gfx::Size bitmap_size_; | |
93 | |
94 base::WeakPtrFactory<CacaWindow> weak_ptr_factory_; | |
95 | |
96 DISALLOW_COPY_AND_ASSIGN(CacaWindow); | |
97 }; | |
98 | |
99 } // namespace ui | |
100 | |
101 #endif // UI_OZONE_PLATFORM_CACA_CACA_WINDOW_H_ | |
OLD | NEW |