Home | History | Annotate | Download | only in aura
      1 // Copyright (c) 2012 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 UI_AURA_REMOTE_WINDOW_TREE_HOST_WIN_H_
      6 #define UI_AURA_REMOTE_WINDOW_TREE_HOST_WIN_H_
      7 
      8 #include <vector>
      9 
     10 #include "base/compiler_specific.h"
     11 #include "base/strings/string16.h"
     12 #include "ui/aura/window_tree_host.h"
     13 #include "ui/base/ime/remote_input_method_delegate_win.h"
     14 #include "ui/events/event.h"
     15 #include "ui/events/event_constants.h"
     16 #include "ui/events/event_source.h"
     17 #include "ui/gfx/native_widget_types.h"
     18 #include "ui/metro_viewer/ime_types.h"
     19 
     20 struct MetroViewerHostMsg_MouseButtonParams;
     21 
     22 namespace base {
     23 class FilePath;
     24 }
     25 
     26 namespace ui {
     27 class RemoteInputMethodPrivateWin;
     28 class ViewProp;
     29 }
     30 
     31 namespace IPC {
     32 class Message;
     33 class Sender;
     34 }
     35 
     36 namespace aura {
     37 
     38 // WindowTreeHost implementaton that receives events from a different
     39 // process. In the case of Windows this is the Windows 8 (aka Metro)
     40 // frontend process, which forwards input events to this class.
     41 class AURA_EXPORT RemoteWindowTreeHostWin
     42     : public WindowTreeHost,
     43       public ui::EventSource,
     44       public ui::internal::RemoteInputMethodDelegateWin {
     45  public:
     46   // Returns the current RemoteWindowTreeHostWin. This does *not* create a
     47   // RemoteWindowTreeHostWin.
     48   static RemoteWindowTreeHostWin* Instance();
     49 
     50   // Returns true if there is a RemoteWindowTreeHostWin and it has a valid
     51   // HWND. A return value of false typically indicates we're not in metro mode.
     52   static bool IsValid();
     53 
     54   // Sets the handle to the remote window. The |remote_window| is the actual
     55   // window owned by the viewer process. Call this before Connected() for some
     56   // customers like input method initialization which needs the handle.
     57   void SetRemoteWindowHandle(HWND remote_window);
     58   HWND remote_window() { return remote_window_; }
     59 
     60   // The |host| can be used when we need to send a message to it.
     61   void Connected(IPC::Sender* host);
     62   // Called when the remote process has closed its IPC connection.
     63   void Disconnected();
     64 
     65   // Called when we have a message from the remote process.
     66   bool OnMessageReceived(const IPC::Message& message);
     67 
     68   void HandleOpenURLOnDesktop(const base::FilePath& shortcut,
     69                               const base::string16& url);
     70 
     71   void HandleWindowSizeChanged(uint32 width, uint32 height);
     72 
     73   // Returns the active ASH root window.
     74   Window* GetAshWindow();
     75 
     76   // Returns true if the remote window is the foreground window according to the
     77   // OS.
     78   bool IsForegroundWindow();
     79 
     80  protected:
     81   RemoteWindowTreeHostWin();
     82   virtual ~RemoteWindowTreeHostWin();
     83 
     84  private:
     85   // IPC message handing methods:
     86   void OnMouseMoved(int32 x, int32 y, int32 flags);
     87   void OnMouseButton(const MetroViewerHostMsg_MouseButtonParams& params);
     88   void OnKeyDown(uint32 vkey,
     89                  uint32 repeat_count,
     90                  uint32 scan_code,
     91                  uint32 flags);
     92   void OnKeyUp(uint32 vkey,
     93                uint32 repeat_count,
     94                uint32 scan_code,
     95                uint32 flags);
     96   void OnChar(uint32 key_code,
     97               uint32 repeat_count,
     98               uint32 scan_code,
     99               uint32 flags);
    100   void OnWindowActivated();
    101   void OnEdgeGesture();
    102   void OnTouchDown(int32 x, int32 y, uint64 timestamp, uint32 pointer_id);
    103   void OnTouchUp(int32 x, int32 y, uint64 timestamp, uint32 pointer_id);
    104   void OnTouchMoved(int32 x, int32 y, uint64 timestamp, uint32 pointer_id);
    105   void OnSetCursorPosAck();
    106 
    107   // For Input Method support:
    108   ui::RemoteInputMethodPrivateWin* GetRemoteInputMethodPrivate();
    109   void OnImeCandidatePopupChanged(bool visible);
    110   void OnImeCompositionChanged(
    111       const base::string16& text,
    112       int32 selection_start,
    113       int32 selection_end,
    114       const std::vector<metro_viewer::UnderlineInfo>& underlines);
    115   void OnImeTextCommitted(const base::string16& text);
    116   void OnImeInputSourceChanged(uint16 language_id, bool is_ime);
    117 
    118   // WindowTreeHost overrides:
    119   virtual ui::EventSource* GetEventSource() OVERRIDE;
    120   virtual gfx::AcceleratedWidget GetAcceleratedWidget() OVERRIDE;
    121   virtual void Show() OVERRIDE;
    122   virtual void Hide() OVERRIDE;
    123   virtual gfx::Rect GetBounds() const OVERRIDE;
    124   virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE;
    125   virtual gfx::Point GetLocationOnNativeScreen() const OVERRIDE;
    126   virtual void SetCapture() OVERRIDE;
    127   virtual void ReleaseCapture() OVERRIDE;
    128   virtual void PostNativeEvent(const base::NativeEvent& native_event) OVERRIDE;
    129   virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE;
    130   virtual void SetCursorNative(gfx::NativeCursor cursor) OVERRIDE;
    131   virtual void MoveCursorToNative(const gfx::Point& location) OVERRIDE;
    132   virtual void OnCursorVisibilityChangedNative(bool show) OVERRIDE;
    133 
    134   // ui::EventSource:
    135   virtual ui::EventProcessor* GetEventProcessor() OVERRIDE;
    136 
    137   // ui::internal::RemoteInputMethodDelegateWin overrides:
    138   virtual void CancelComposition() OVERRIDE;
    139   virtual void OnTextInputClientUpdated(
    140       const std::vector<int32>& input_scopes,
    141       const std::vector<gfx::Rect>& composition_character_bounds) OVERRIDE;
    142 
    143   // Helper function to dispatch a keyboard message to the desired target.
    144   // The default target is the WindowEventDispatcher. For nested message loop
    145   // invocations we post a synthetic keyboard message directly into the message
    146   // loop. The dispatcher for the nested loop would then decide how this
    147   // message is routed.
    148   void DispatchKeyboardMessage(ui::EventType type,
    149                                uint32 vkey,
    150                                uint32 repeat_count,
    151                                uint32 scan_code,
    152                                uint32 flags,
    153                                bool is_character);
    154 
    155   // Sets the event flags. |flags| is a bitmask of EventFlags. If there is a
    156   // change the system virtual key state is updated as well. This way if chrome
    157   // queries for key state it matches that of event being dispatched.
    158   void SetEventFlags(uint32 flags);
    159 
    160   uint32 mouse_event_flags() const {
    161     return event_flags_ & (ui::EF_LEFT_MOUSE_BUTTON |
    162                            ui::EF_MIDDLE_MOUSE_BUTTON |
    163                            ui::EF_RIGHT_MOUSE_BUTTON);
    164   }
    165 
    166   uint32 key_event_flags() const {
    167     return event_flags_ & (ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN |
    168                            ui::EF_ALT_DOWN | ui::EF_CAPS_LOCK_DOWN);
    169   }
    170 
    171   HWND remote_window_;
    172   IPC::Sender* host_;
    173   scoped_ptr<ui::ViewProp> prop_;
    174 
    175   // Set to true if we need to ignore mouse messages until the SetCursorPos
    176   // operation is acked by the viewer.
    177   bool ignore_mouse_moves_until_set_cursor_ack_;
    178 
    179   // Tracking last click event for synthetically generated mouse events.
    180   scoped_ptr<ui::MouseEvent> last_mouse_click_event_;
    181 
    182   // State of the keyboard/mouse at the time of the last input event. See
    183   // description of SetEventFlags().
    184   uint32 event_flags_;
    185 
    186   // Current size of this root window.
    187   gfx::Size window_size_;
    188 
    189   DISALLOW_COPY_AND_ASSIGN(RemoteWindowTreeHostWin);
    190 };
    191 
    192 }  // namespace aura
    193 
    194 #endif  // UI_AURA_REMOTE_WINDOW_TREE_HOST_WIN_H_
    195