| 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 #include "ui/ozone/platform/caca/caca_window.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/location.h" | |
| 9 #include "base/logging.h" | |
| 10 #include "base/single_thread_task_runner.h" | |
| 11 #include "base/strings/utf_string_conversions.h" | |
| 12 #include "base/threading/thread_task_runner_handle.h" | |
| 13 #include "base/trace_event/trace_event.h" | |
| 14 #include "ui/events/ozone/events_ozone.h" | |
| 15 #include "ui/events/platform/platform_event_source.h" | |
| 16 #include "ui/ozone/platform/caca/caca_event_source.h" | |
| 17 #include "ui/ozone/platform/caca/caca_window_manager.h" | |
| 18 #include "ui/platform_window/platform_window_delegate.h" | |
| 19 | |
| 20 namespace ui { | |
| 21 | |
| 22 namespace { | |
| 23 | |
| 24 // Size of initial cnavas (in characters). | |
| 25 const int kDefaultCanvasWidth = 160; | |
| 26 const int kDefaultCanvasHeight = 48; | |
| 27 | |
| 28 } // namespace | |
| 29 | |
| 30 // TODO(dnicoara) As an optimization, |bitmap_size_| should be scaled based on | |
| 31 // |physical_size_| and font size. | |
| 32 CacaWindow::CacaWindow(PlatformWindowDelegate* delegate, | |
| 33 CacaWindowManager* manager, | |
| 34 CacaEventSource* event_source, | |
| 35 const gfx::Rect& bounds) | |
| 36 : delegate_(delegate), | |
| 37 manager_(manager), | |
| 38 event_source_(event_source), | |
| 39 weak_ptr_factory_(this) { | |
| 40 widget_ = manager_->AddWindow(this); | |
| 41 ui::PlatformEventSource::GetInstance()->AddPlatformEventDispatcher(this); | |
| 42 delegate_->OnAcceleratedWidgetAvailable(widget_, 1.f); | |
| 43 } | |
| 44 | |
| 45 CacaWindow::~CacaWindow() { | |
| 46 ui::PlatformEventSource::GetInstance()->RemovePlatformEventDispatcher(this); | |
| 47 manager_->RemoveWindow(widget_, this); | |
| 48 } | |
| 49 | |
| 50 bool CacaWindow::Initialize() { | |
| 51 if (display_) | |
| 52 return true; | |
| 53 | |
| 54 canvas_.reset(caca_create_canvas(kDefaultCanvasWidth, kDefaultCanvasHeight)); | |
| 55 if (!canvas_) { | |
| 56 PLOG(ERROR) << "failed to create libcaca canvas"; | |
| 57 return false; | |
| 58 } | |
| 59 | |
| 60 display_.reset(caca_create_display(canvas_.get())); | |
| 61 if (!display_) { | |
| 62 PLOG(ERROR) << "failed to initialize libcaca display"; | |
| 63 return false; | |
| 64 } | |
| 65 | |
| 66 caca_set_cursor(display_.get(), 1); | |
| 67 caca_set_display_title(display_.get(), "Ozone Content Shell"); | |
| 68 | |
| 69 UpdateDisplaySize(); | |
| 70 | |
| 71 TryProcessingEvent(); | |
| 72 | |
| 73 return true; | |
| 74 } | |
| 75 | |
| 76 void CacaWindow::TryProcessingEvent() { | |
| 77 event_source_->TryProcessingEvent(this); | |
| 78 | |
| 79 // Caca uses a poll based event retrieval. Since we don't want to block we'd | |
| 80 // either need to spin up a new thread or just poll. For simplicity just poll | |
| 81 // for messages. | |
| 82 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | |
| 83 FROM_HERE, base::Bind(&CacaWindow::TryProcessingEvent, | |
| 84 weak_ptr_factory_.GetWeakPtr()), | |
| 85 base::TimeDelta::FromMilliseconds(10)); | |
| 86 } | |
| 87 | |
| 88 void CacaWindow::UpdateDisplaySize() { | |
| 89 physical_size_.SetSize(caca_get_canvas_width(canvas_.get()), | |
| 90 caca_get_canvas_height(canvas_.get())); | |
| 91 | |
| 92 bitmap_size_.SetSize(caca_get_display_width(display_.get()), | |
| 93 caca_get_display_height(display_.get())); | |
| 94 } | |
| 95 | |
| 96 void CacaWindow::OnCacaResize() { | |
| 97 UpdateDisplaySize(); | |
| 98 | |
| 99 delegate_->OnBoundsChanged(gfx::Rect(bitmap_size_)); | |
| 100 } | |
| 101 | |
| 102 void CacaWindow::OnCacaQuit() { | |
| 103 delegate_->OnCloseRequest(); | |
| 104 } | |
| 105 | |
| 106 | |
| 107 void CacaWindow::OnCacaEvent(ui::Event* event) { | |
| 108 DispatchEventFromNativeUiEvent( | |
| 109 event, base::Bind(&PlatformWindowDelegate::DispatchEvent, | |
| 110 base::Unretained(delegate_))); | |
| 111 } | |
| 112 | |
| 113 gfx::Rect CacaWindow::GetBounds() { return gfx::Rect(bitmap_size_); } | |
| 114 | |
| 115 void CacaWindow::SetBounds(const gfx::Rect& bounds) {} | |
| 116 | |
| 117 void CacaWindow::Show() {} | |
| 118 | |
| 119 void CacaWindow::Hide() {} | |
| 120 | |
| 121 void CacaWindow::Close() {} | |
| 122 | |
| 123 void CacaWindow::SetCapture() {} | |
| 124 | |
| 125 void CacaWindow::ReleaseCapture() {} | |
| 126 | |
| 127 void CacaWindow::ToggleFullscreen() {} | |
| 128 | |
| 129 void CacaWindow::Maximize() {} | |
| 130 | |
| 131 void CacaWindow::Minimize() {} | |
| 132 | |
| 133 void CacaWindow::Restore() {} | |
| 134 | |
| 135 void CacaWindow::SetCursor(PlatformCursor cursor) {} | |
| 136 | |
| 137 void CacaWindow::MoveCursorTo(const gfx::Point& location) {} | |
| 138 | |
| 139 void CacaWindow::ConfineCursorToBounds(const gfx::Rect& bounds) {} | |
| 140 | |
| 141 PlatformImeController* CacaWindow::GetPlatformImeController() { | |
| 142 return nullptr; | |
| 143 } | |
| 144 | |
| 145 void CacaWindow::SetTitle(const base::string16& title) { | |
| 146 caca_set_display_title(display_.get(), UTF16ToUTF8(title).c_str()); | |
| 147 } | |
| 148 | |
| 149 bool CacaWindow::CanDispatchEvent(const PlatformEvent& event) { return true; } | |
| 150 | |
| 151 uint32_t CacaWindow::DispatchEvent(const PlatformEvent& ne) { | |
| 152 // We don't dispatch events via PlatformEventSource. | |
| 153 NOTREACHED(); | |
| 154 return ui::POST_DISPATCH_STOP_PROPAGATION; | |
| 155 } | |
| 156 | |
| 157 } // namespace ui | |
| OLD | NEW |