OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef APPS_MOTERM_MOTERM_VIEW_H_ |
| 6 #define APPS_MOTERM_MOTERM_VIEW_H_ |
| 7 |
| 8 #include "apps/moterm/gl_helper.h" |
| 9 #include "apps/moterm/moterm_driver.h" |
| 10 #include "apps/moterm/moterm_model.h" |
| 11 #include "base/macros.h" |
| 12 #include "base/memory/weak_ptr.h" |
| 13 #include "mojo/common/weak_binding_set.h" |
| 14 #include "mojo/public/cpp/application/interface_factory.h" |
| 15 #include "mojo/public/cpp/application/service_provider_impl.h" |
| 16 #include "mojo/public/cpp/bindings/callback.h" |
| 17 #include "mojo/public/cpp/bindings/interface_request.h" |
| 18 #include "mojo/services/surfaces/public/interfaces/surface_id.mojom.h" |
| 19 #include "mojo/services/terminal/public/interfaces/terminal.mojom.h" |
| 20 #include "mojo/services/view_manager/public/cpp/view_observer.h" |
| 21 #include "skia/ext/refptr.h" |
| 22 #include "third_party/skia/include/core/SkBitmapDevice.h" |
| 23 #include "third_party/skia/include/core/SkTypeface.h" |
| 24 |
| 25 namespace mojo { |
| 26 class Shell; |
| 27 } |
| 28 |
| 29 class MotermView : public mojo::ViewObserver, |
| 30 public GlHelper::Client, |
| 31 public MotermDriver::Client, |
| 32 public mojo::InterfaceFactory<mojo::terminal::Terminal>, |
| 33 public mojo::terminal::Terminal { |
| 34 public: |
| 35 MotermView( |
| 36 mojo::Shell* shell, |
| 37 mojo::View* view, |
| 38 mojo::InterfaceRequest<mojo::ServiceProvider> service_provider_request); |
| 39 ~MotermView() override; |
| 40 |
| 41 private: |
| 42 // |mojo::ViewObserver|: |
| 43 void OnViewDestroyed(mojo::View* view) override; |
| 44 void OnViewBoundsChanged(mojo::View* view, |
| 45 const mojo::Rect& old_bounds, |
| 46 const mojo::Rect& new_bounds) override; |
| 47 void OnViewInputEvent(mojo::View* view, const mojo::EventPtr& event) override; |
| 48 |
| 49 // |GlHelper::Client|: |
| 50 void OnSurfaceIdChanged(mojo::SurfaceIdPtr surface_id) override; |
| 51 void OnContextLost() override; |
| 52 void OnFrameDisplayed(uint32_t frame_id) override; |
| 53 |
| 54 // |MotermDriver::Client|: |
| 55 void OnDataReceived(const void* bytes, size_t num_bytes) override; |
| 56 void OnClosed() override; |
| 57 void OnDestroyed() override; |
| 58 |
| 59 // |mojo::InterfaceFactory<mojo::terminal::Terminal>|: |
| 60 void Create( |
| 61 mojo::ApplicationConnection* connection, |
| 62 mojo::InterfaceRequest<mojo::terminal::Terminal> request) override; |
| 63 |
| 64 // |mojo::terminal::Terminal| implementation: |
| 65 void Connect(mojo::InterfaceRequest<mojo::files::File> terminal_file, |
| 66 bool force, |
| 67 const ConnectCallback& callback) override; |
| 68 void ConnectToClient(mojo::terminal::TerminalClientPtr terminal_client, |
| 69 bool force, |
| 70 const ConnectToClientCallback& callback) override; |
| 71 void GetSize(const GetSizeCallback& callback) override; |
| 72 void SetSize(uint32_t rows, |
| 73 uint32_t columns, |
| 74 bool reset, |
| 75 const SetSizeCallback& callback) override; |
| 76 |
| 77 // If |force| is true, it will draw everything. Otherwise it will draw only if |
| 78 // |model_state_changes_| is dirty. |
| 79 void Draw(bool force); |
| 80 |
| 81 void OnKeyPressed(const mojo::EventPtr& key_event); |
| 82 |
| 83 mojo::View* const view_; |
| 84 GlHelper gl_helper_; |
| 85 |
| 86 // TODO(vtl): Consider the structure of this app. Do we really want the "view" |
| 87 // owning the model? |
| 88 // The terminal model. |
| 89 MotermModel model_; |
| 90 // State changes to the model since last draw. |
| 91 MotermModel::StateChanges model_state_changes_; |
| 92 |
| 93 base::WeakPtr<MotermDriver> driver_; |
| 94 // If set, called when we get |OnClosed()| or |OnDestroyed()| from the driver. |
| 95 mojo::Closure on_closed_callback_; |
| 96 |
| 97 mojo::ServiceProviderImpl service_provider_impl_; |
| 98 mojo::WeakBindingSet<mojo::terminal::Terminal> terminal_bindings_; |
| 99 |
| 100 // TODO(vtl): For some reason, drawing while a frame is already pending (i.e., |
| 101 // we've submitted it but haven't gotten a callback) interacts badly with |
| 102 // resizing -- sometimes this results in us losing all future |
| 103 // |OnViewBoundsChanged()| messages. So, for now, don't submit frames in that |
| 104 // case. |
| 105 bool frame_pending_; |
| 106 // If we skip drawing despite being forced to, we should force the next draw. |
| 107 bool force_next_draw_; |
| 108 |
| 109 skia::RefPtr<SkTypeface> regular_typeface_; |
| 110 |
| 111 int ascent_; |
| 112 int line_height_; |
| 113 int advance_width_; |
| 114 |
| 115 skia::RefPtr<SkBitmapDevice> bitmap_device_; |
| 116 |
| 117 DISALLOW_COPY_AND_ASSIGN(MotermView); |
| 118 }; |
| 119 |
| 120 #endif // APPS_MOTERM_MOTERM_VIEW_H_ |
OLD | NEW |