Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(82)

Side by Side Diff: ui/ozone/platform/caca/caca_window.cc

Issue 387953004: ozone: caca: Convert to PlatformWindow (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase & nits Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/ozone/platform/caca/caca_window.h ('k') | ui/ozone/platform/caca/caca_window_manager.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 #include "ui/ozone/platform/caca/caca_window.h"
6
7 #include "base/bind.h"
8 #include "base/debug/trace_event.h"
9 #include "base/logging.h"
10 #include "base/message_loop/message_loop.h"
11 #include "ui/events/platform/platform_event_source.h"
12 #include "ui/ozone/platform/caca/caca_event_factory.h"
13 #include "ui/ozone/platform/caca/caca_window_manager.h"
14 #include "ui/platform_window/platform_window_delegate.h"
15
16 namespace ui {
17
18 namespace {
19
20 // Size of initial cnavas (in characters).
21 const int kDefaultCanvasWidth = 160;
22 const int kDefaultCanvasHeight = 48;
23
24 } // namespace
25
26 // TODO(dnicoara) As an optimization, |bitmap_size_| should be scaled based on
27 // |physical_size_| and font size.
28 CacaWindow::CacaWindow(PlatformWindowDelegate* delegate,
29 CacaWindowManager* manager,
30 CacaEventFactory* event_factory,
31 const gfx::Rect& bounds)
32 : delegate_(delegate),
33 manager_(manager),
34 event_factory_(event_factory),
35 weak_ptr_factory_(this) {
36 widget_ = manager_->AddWindow(this);
37 ui::PlatformEventSource::GetInstance()->AddPlatformEventDispatcher(this);
38 delegate_->OnAcceleratedWidgetAvailable(widget_);
39 }
40
41 CacaWindow::~CacaWindow() {
42 ui::PlatformEventSource::GetInstance()->RemovePlatformEventDispatcher(this);
43 manager_->RemoveWindow(widget_, this);
44 }
45
46 bool CacaWindow::Initialize() {
47 if (display_)
48 return true;
49
50 canvas_.reset(caca_create_canvas(kDefaultCanvasWidth, kDefaultCanvasHeight));
51 if (!canvas_) {
52 PLOG(ERROR) << "failed to create libcaca canvas";
53 return false;
54 }
55
56 display_.reset(caca_create_display(canvas_.get()));
57 if (!display_) {
58 PLOG(ERROR) << "failed to initialize libcaca display";
59 return false;
60 }
61
62 caca_set_cursor(display_.get(), 1);
63 caca_set_display_title(display_.get(), "Ozone Content Shell");
64
65 UpdateDisplaySize();
66
67 TryProcessingEvent();
68
69 return true;
70 }
71
72 void CacaWindow::TryProcessingEvent() {
73 event_factory_->TryProcessingEvent(this);
74
75 // Caca uses a poll based event retrieval. Since we don't want to block we'd
76 // either need to spin up a new thread or just poll. For simplicity just poll
77 // for messages.
78 base::MessageLoop::current()->PostDelayedTask(
79 FROM_HERE,
80 base::Bind(&CacaWindow::TryProcessingEvent,
81 weak_ptr_factory_.GetWeakPtr()),
82 base::TimeDelta::FromMilliseconds(10));
83 }
84
85 void CacaWindow::UpdateDisplaySize() {
86 physical_size_.SetSize(caca_get_canvas_width(canvas_.get()),
87 caca_get_canvas_height(canvas_.get()));
88
89 bitmap_size_.SetSize(caca_get_display_width(display_.get()),
90 caca_get_display_height(display_.get()));
91 }
92
93 void CacaWindow::OnCacaResize() {
94 UpdateDisplaySize();
95
96 delegate_->OnBoundsChanged(gfx::Rect(bitmap_size_));
97 }
98
99 void CacaWindow::OnCacaQuit() {
100 delegate_->OnCloseRequest();
101 }
102
103
104 void CacaWindow::OnCacaEvent(ui::Event* event) {
105 delegate_->DispatchEvent(event);
106 }
107
108 gfx::Rect CacaWindow::GetBounds() { return gfx::Rect(bitmap_size_); }
109
110 void CacaWindow::SetBounds(const gfx::Rect& bounds) {}
111
112 void CacaWindow::Show() {}
113
114 void CacaWindow::Hide() {}
115
116 void CacaWindow::Close() {}
117
118 void CacaWindow::SetCapture() {}
119
120 void CacaWindow::ReleaseCapture() {}
121
122 void CacaWindow::ToggleFullscreen() {}
123
124 void CacaWindow::Maximize() {}
125
126 void CacaWindow::Minimize() {}
127
128 void CacaWindow::Restore() {}
129
130 bool CacaWindow::CanDispatchEvent(const PlatformEvent& event) { return true; }
131
132 uint32_t CacaWindow::DispatchEvent(const PlatformEvent& ne) {
133 // We don't dispatch events via PlatformEventSource.
134 NOTREACHED();
135 return ui::POST_DISPATCH_STOP_PROPAGATION;
136 }
137
138 } // namespace ui
OLDNEW
« no previous file with comments | « ui/ozone/platform/caca/caca_window.h ('k') | ui/ozone/platform/caca/caca_window_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698