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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 // connection context argument. | 58 // connection context argument. |
59 service_provider_impl_.Bind(mojo::ConnectionContext(), | 59 service_provider_impl_.Bind(mojo::ConnectionContext(), |
60 service_provider_request.Pass()); | 60 service_provider_request.Pass()); |
61 service_provider_impl_.AddService<mojo::terminal::Terminal>([this]( | 61 service_provider_impl_.AddService<mojo::terminal::Terminal>([this]( |
62 const mojo::ConnectionContext& connection_context, | 62 const mojo::ConnectionContext& connection_context, |
63 mojo::InterfaceRequest<mojo::terminal::Terminal> terminal_request) { | 63 mojo::InterfaceRequest<mojo::terminal::Terminal> terminal_request) { |
64 terminal_bindings_.AddBinding(this, terminal_request.Pass()); | 64 terminal_bindings_.AddBinding(this, terminal_request.Pass()); |
65 }); | 65 }); |
66 } | 66 } |
67 | 67 |
68 regular_typeface_ = skia::AdoptRef(SkTypeface::CreateFromStream( | 68 regular_typeface_ = SkTypeface::MakeFromStream( |
69 new SkMemoryStream(font_data::kDejaVuSansMonoRegular.data, | 69 new SkMemoryStream(font_data::kDejaVuSansMonoRegular.data, |
70 font_data::kDejaVuSansMonoRegular.size))); | 70 font_data::kDejaVuSansMonoRegular.size)); |
71 | 71 |
72 // TODO(vtl): This duplicates some code. | 72 // TODO(vtl): This duplicates some code. |
73 SkPaint fg_paint; | 73 SkPaint fg_paint; |
74 fg_paint.setTypeface(regular_typeface_.get()); | 74 fg_paint.setTypeface(regular_typeface_); |
75 fg_paint.setTextSize(16); | 75 fg_paint.setTextSize(16); |
76 // Figure out appropriate metrics. | 76 // Figure out appropriate metrics. |
77 SkPaint::FontMetrics fm = {}; | 77 SkPaint::FontMetrics fm = {}; |
78 fg_paint.getFontMetrics(&fm); | 78 fg_paint.getFontMetrics(&fm); |
79 ascent_ = static_cast<int>(ceilf(-fm.fAscent)); | 79 ascent_ = static_cast<int>(ceilf(-fm.fAscent)); |
80 line_height_ = ascent_ + static_cast<int>(ceilf(fm.fDescent + fm.fLeading)); | 80 line_height_ = ascent_ + static_cast<int>(ceilf(fm.fDescent + fm.fLeading)); |
81 DCHECK_GT(line_height_, 0); | 81 DCHECK_GT(line_height_, 0); |
82 // To figure out the advance width, measure an X. Better hope the font is | 82 // To figure out the advance width, measure an X. Better hope the font is |
83 // monospace. | 83 // monospace. |
84 advance_width_ = static_cast<int>(ceilf(fg_paint.measureText("X", 1))); | 84 advance_width_ = static_cast<int>(ceilf(fg_paint.measureText("X", 1))); |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 void MotermView::DrawContent( | 268 void MotermView::DrawContent( |
269 const mojo::skia::GaneshContext::Scope& ganesh_scope, | 269 const mojo::skia::GaneshContext::Scope& ganesh_scope, |
270 const mojo::Size& texture_size, | 270 const mojo::Size& texture_size, |
271 SkCanvas* canvas) { | 271 SkCanvas* canvas) { |
272 canvas->clear(SK_ColorBLACK); | 272 canvas->clear(SK_ColorBLACK); |
273 | 273 |
274 SkPaint bg_paint; | 274 SkPaint bg_paint; |
275 bg_paint.setStyle(SkPaint::kFill_Style); | 275 bg_paint.setStyle(SkPaint::kFill_Style); |
276 | 276 |
277 SkPaint fg_paint; | 277 SkPaint fg_paint; |
278 fg_paint.setTypeface(regular_typeface_.get()); | 278 fg_paint.setTypeface(regular_typeface_); |
279 fg_paint.setTextSize(16); | 279 fg_paint.setTextSize(16); |
280 fg_paint.setTextEncoding(SkPaint::kUTF32_TextEncoding); | 280 fg_paint.setTextEncoding(SkPaint::kUTF32_TextEncoding); |
281 | 281 |
282 MotermModel::Size size = model_.GetSize(); | 282 MotermModel::Size size = model_.GetSize(); |
283 int y = 0; | 283 int y = 0; |
284 for (unsigned i = 0; i < size.rows; i++, y += line_height_) { | 284 for (unsigned i = 0; i < size.rows; i++, y += line_height_) { |
285 int x = 0; | 285 int x = 0; |
286 for (unsigned j = 0; j < size.columns; j++, x += advance_width_) { | 286 for (unsigned j = 0; j < size.columns; j++, x += advance_width_) { |
287 MotermModel::CharacterInfo ch = | 287 MotermModel::CharacterInfo ch = |
288 model_.GetCharacterInfoAt(MotermModel::Position(i, j)); | 288 model_.GetCharacterInfoAt(MotermModel::Position(i, j)); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 | 334 |
335 void MotermView::OnKeyPressed(mojo::EventPtr key_event) { | 335 void MotermView::OnKeyPressed(mojo::EventPtr key_event) { |
336 std::string input_sequence = | 336 std::string input_sequence = |
337 GetInputSequenceForKeyPressedEvent(*key_event, keypad_application_mode_); | 337 GetInputSequenceForKeyPressedEvent(*key_event, keypad_application_mode_); |
338 if (input_sequence.empty()) | 338 if (input_sequence.empty()) |
339 return; | 339 return; |
340 | 340 |
341 if (driver_) | 341 if (driver_) |
342 driver_->SendData(input_sequence.data(), input_sequence.size()); | 342 driver_->SendData(input_sequence.data(), input_sequence.size()); |
343 } | 343 } |
OLD | NEW |