| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "apps/moterm/moterm_view.h" | 5 #include "apps/moterm/moterm_view.h" |
| 6 | 6 |
| 7 #ifndef GL_GLEXT_PROTOTYPES | 7 #ifndef GL_GLEXT_PROTOTYPES |
| 8 #define GL_GLEXT_PROTOTYPES | 8 #define GL_GLEXT_PROTOTYPES |
| 9 #endif | 9 #endif |
| 10 | 10 |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 const mojo::Rect& old_bounds, | 111 const mojo::Rect& old_bounds, |
| 112 const mojo::Rect& new_bounds) { | 112 const mojo::Rect& new_bounds) { |
| 113 DCHECK_EQ(view, view_); | 113 DCHECK_EQ(view, view_); |
| 114 gl_helper_.SetSurfaceSize(RectToSize(view_->bounds())); | 114 gl_helper_.SetSurfaceSize(RectToSize(view_->bounds())); |
| 115 bitmap_device_.clear(); | 115 bitmap_device_.clear(); |
| 116 Draw(true); | 116 Draw(true); |
| 117 } | 117 } |
| 118 | 118 |
| 119 void MotermView::OnViewInputEvent(mojo::View* view, | 119 void MotermView::OnViewInputEvent(mojo::View* view, |
| 120 const mojo::EventPtr& event) { | 120 const mojo::EventPtr& event) { |
| 121 if (event->action == mojo::EVENT_TYPE_KEY_PRESSED) | 121 if (event->action == mojo::EventType::KEY_PRESSED) |
| 122 OnKeyPressed(event); | 122 OnKeyPressed(event); |
| 123 } | 123 } |
| 124 | 124 |
| 125 void MotermView::OnSurfaceIdChanged(mojo::SurfaceIdPtr surface_id) { | 125 void MotermView::OnSurfaceIdChanged(mojo::SurfaceIdPtr surface_id) { |
| 126 view_->SetSurfaceId(surface_id.Pass()); | 126 view_->SetSurfaceId(surface_id.Pass()); |
| 127 } | 127 } |
| 128 | 128 |
| 129 void MotermView::OnContextLost() { | 129 void MotermView::OnContextLost() { |
| 130 // TODO(vtl): We'll need to force a draw when we regain a context. | 130 // TODO(vtl): We'll need to force a draw when we regain a context. |
| 131 } | 131 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 void MotermView::Connect( | 176 void MotermView::Connect( |
| 177 mojo::InterfaceRequest<mojo::files::File> terminal_file, | 177 mojo::InterfaceRequest<mojo::files::File> terminal_file, |
| 178 bool force, | 178 bool force, |
| 179 const ConnectCallback& callback) { | 179 const ConnectCallback& callback) { |
| 180 if (driver_) { | 180 if (driver_) { |
| 181 // We already have a connection. | 181 // We already have a connection. |
| 182 if (force) { | 182 if (force) { |
| 183 OnClosed(); | 183 OnClosed(); |
| 184 } else { | 184 } else { |
| 185 // TODO(vtl): Is this error code right? | 185 // TODO(vtl): Is this error code right? |
| 186 callback.Run(mojo::files::ERROR_UNAVAILABLE); | 186 callback.Run(mojo::files::Error::UNAVAILABLE); |
| 187 return; | 187 return; |
| 188 } | 188 } |
| 189 } | 189 } |
| 190 | 190 |
| 191 driver_ = MotermDriver::Create(this, terminal_file.Pass()); | 191 driver_ = MotermDriver::Create(this, terminal_file.Pass()); |
| 192 DCHECK(on_closed_callback_.is_null()); | 192 DCHECK(on_closed_callback_.is_null()); |
| 193 on_closed_callback_ = [callback] { callback.Run(mojo::files::ERROR_OK); }; | 193 on_closed_callback_ = [callback] { callback.Run(mojo::files::Error::OK); }; |
| 194 } | 194 } |
| 195 | 195 |
| 196 void MotermView::ConnectToClient( | 196 void MotermView::ConnectToClient( |
| 197 mojo::terminal::TerminalClientPtr terminal_client, | 197 mojo::terminal::TerminalClientPtr terminal_client, |
| 198 bool force, | 198 bool force, |
| 199 const ConnectToClientCallback& callback) { | 199 const ConnectToClientCallback& callback) { |
| 200 if (driver_) { | 200 if (driver_) { |
| 201 // We already have a connection. | 201 // We already have a connection. |
| 202 if (force) { | 202 if (force) { |
| 203 OnClosed(); | 203 OnClosed(); |
| 204 } else { | 204 } else { |
| 205 // TODO(vtl): Is this error code right? | 205 // TODO(vtl): Is this error code right? |
| 206 callback.Run(mojo::files::ERROR_UNAVAILABLE); | 206 callback.Run(mojo::files::Error::UNAVAILABLE); |
| 207 return; | 207 return; |
| 208 } | 208 } |
| 209 } | 209 } |
| 210 | 210 |
| 211 mojo::files::FilePtr file; | 211 mojo::files::FilePtr file; |
| 212 driver_ = MotermDriver::Create(this, GetProxy(&file)); | 212 driver_ = MotermDriver::Create(this, GetProxy(&file)); |
| 213 terminal_client->ConnectToTerminal(file.Pass()); | 213 terminal_client->ConnectToTerminal(file.Pass()); |
| 214 DCHECK(on_closed_callback_.is_null()); | 214 DCHECK(on_closed_callback_.is_null()); |
| 215 on_closed_callback_ = [callback] { callback.Run(mojo::files::ERROR_OK); }; | 215 on_closed_callback_ = [callback] { callback.Run(mojo::files::Error::OK); }; |
| 216 } | 216 } |
| 217 | 217 |
| 218 void MotermView::GetSize(const GetSizeCallback& callback) { | 218 void MotermView::GetSize(const GetSizeCallback& callback) { |
| 219 MotermModel::Size size = model_.GetSize(); | 219 MotermModel::Size size = model_.GetSize(); |
| 220 callback.Run(mojo::files::ERROR_OK, size.rows, size.columns); | 220 callback.Run(mojo::files::Error::OK, size.rows, size.columns); |
| 221 } | 221 } |
| 222 | 222 |
| 223 void MotermView::SetSize(uint32_t rows, | 223 void MotermView::SetSize(uint32_t rows, |
| 224 uint32_t columns, | 224 uint32_t columns, |
| 225 bool reset, | 225 bool reset, |
| 226 const SetSizeCallback& callback) { | 226 const SetSizeCallback& callback) { |
| 227 if (!rows) { | 227 if (!rows) { |
| 228 rows = std::max(1u, std::min(MotermModel::kMaxRows, | 228 rows = std::max(1u, std::min(MotermModel::kMaxRows, |
| 229 static_cast<uint32_t>(view_->bounds().height) / | 229 static_cast<uint32_t>(view_->bounds().height) / |
| 230 line_height_)); | 230 line_height_)); |
| 231 } | 231 } |
| 232 if (!columns) { | 232 if (!columns) { |
| 233 columns = | 233 columns = |
| 234 std::max(1u, std::min(MotermModel::kMaxColumns, | 234 std::max(1u, std::min(MotermModel::kMaxColumns, |
| 235 static_cast<uint32_t>(view_->bounds().width) / | 235 static_cast<uint32_t>(view_->bounds().width) / |
| 236 advance_width_)); | 236 advance_width_)); |
| 237 } | 237 } |
| 238 | 238 |
| 239 model_.SetSize(MotermModel::Size(rows, columns), reset); | 239 model_.SetSize(MotermModel::Size(rows, columns), reset); |
| 240 callback.Run(mojo::files::ERROR_OK, rows, columns); | 240 callback.Run(mojo::files::Error::OK, rows, columns); |
| 241 | 241 |
| 242 Draw(false); | 242 Draw(false); |
| 243 } | 243 } |
| 244 | 244 |
| 245 void MotermView::Draw(bool force) { | 245 void MotermView::Draw(bool force) { |
| 246 // TODO(vtl): See TODO above |frame_pending_| in the class declaration. | 246 // TODO(vtl): See TODO above |frame_pending_| in the class declaration. |
| 247 if (frame_pending_) { | 247 if (frame_pending_) { |
| 248 force_next_draw_ |= force; | 248 force_next_draw_ |= force; |
| 249 return; | 249 return; |
| 250 } | 250 } |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 | 346 |
| 347 void MotermView::OnKeyPressed(const mojo::EventPtr& key_event) { | 347 void MotermView::OnKeyPressed(const mojo::EventPtr& key_event) { |
| 348 std::string input_sequence = | 348 std::string input_sequence = |
| 349 GetInputSequenceForKeyPressedEvent(*key_event, keypad_application_mode_); | 349 GetInputSequenceForKeyPressedEvent(*key_event, keypad_application_mode_); |
| 350 if (input_sequence.empty()) | 350 if (input_sequence.empty()) |
| 351 return; | 351 return; |
| 352 | 352 |
| 353 if (driver_) | 353 if (driver_) |
| 354 driver_->SendData(input_sequence.data(), input_sequence.size()); | 354 driver_->SendData(input_sequence.data(), input_sequence.size()); |
| 355 } | 355 } |
| OLD | NEW |