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_ROOT_WINDOW_HOST_WIN_H_
      6 #define UI_AURA_REMOTE_ROOT_WINDOW_HOST_WIN_H_
      7 
      8 #include <vector>
      9 
     10 #include "base/callback.h"
     11 #include "base/compiler_specific.h"
     12 #include "base/strings/string16.h"
     13 #include "ui/aura/root_window_host.h"
     14 #include "ui/base/events/event.h"
     15 #include "ui/base/events/event_constants.h"
     16 #include "ui/gfx/native_widget_types.h"
     17 
     18 namespace base {
     19 class FilePath;
     20 }
     21 
     22 namespace ui {
     23 class ViewProp;
     24 }
     25 
     26 namespace IPC {
     27 class Message;
     28 class Sender;
     29 }
     30 
     31 namespace aura {
     32 
     33 typedef base::Callback<void(const base::FilePath&, int, void*)>
     34     OpenFileCompletion;
     35 
     36 typedef base::Callback<void(const std::vector<base::FilePath>&, void*)>
     37     OpenMultipleFilesCompletion;
     38 
     39 typedef base::Callback<void(const base::FilePath&, int, void*)>
     40     SaveFileCompletion;
     41 
     42 typedef base::Callback<void(const base::FilePath&, int, void*)>
     43     SelectFolderCompletion;
     44 
     45 typedef base::Callback<void(void*)> FileSelectionCanceled;
     46 
     47 // Handles the open file operation for Metro Chrome Ash. The on_success
     48 // callback passed in is invoked when we receive the opened file name from
     49 // the metro viewer. The on failure callback is invoked on failure.
     50 AURA_EXPORT void HandleOpenFile(const base::string16& title,
     51                                 const base::FilePath& default_path,
     52                                 const base::string16& filter,
     53                                 const OpenFileCompletion& on_success,
     54                                 const FileSelectionCanceled& on_failure);
     55 
     56 // Handles the open multiple file operation for Metro Chrome Ash. The
     57 // on_success callback passed in is invoked when we receive the opened file
     58 // names from the metro viewer. The on failure callback is invoked on failure.
     59 AURA_EXPORT void HandleOpenMultipleFiles(
     60     const base::string16& title,
     61     const base::FilePath& default_path,
     62     const base::string16& filter,
     63     const OpenMultipleFilesCompletion& on_success,
     64     const FileSelectionCanceled& on_failure);
     65 
     66 // Handles the save file operation for Metro Chrome Ash. The on_success
     67 // callback passed in is invoked when we receive the saved file name from
     68 // the metro viewer. The on failure callback is invoked on failure.
     69 AURA_EXPORT void HandleSaveFile(const base::string16& title,
     70                                 const base::FilePath& default_path,
     71                                 const base::string16& filter,
     72                                 int filter_index,
     73                                 const base::string16& default_extension,
     74                                 const SaveFileCompletion& on_success,
     75                                 const FileSelectionCanceled& on_failure);
     76 
     77 // Handles the select folder for Metro Chrome Ash. The on_success
     78 // callback passed in is invoked when we receive the folder name from the
     79 // metro viewer. The on failure callback is invoked on failure.
     80 AURA_EXPORT void HandleSelectFolder(const base::string16& title,
     81                                     const SelectFolderCompletion& on_success,
     82                                     const FileSelectionCanceled& on_failure);
     83 
     84 // RootWindowHost implementaton that receives events from a different
     85 // process. In the case of Windows this is the Windows 8 (aka Metro)
     86 // frontend process, which forwards input events to this class.
     87 class AURA_EXPORT RemoteRootWindowHostWin : public RootWindowHost {
     88  public:
     89   static RemoteRootWindowHostWin* Instance();
     90   static RemoteRootWindowHostWin* Create(const gfx::Rect& bounds);
     91 
     92   // Called when the remote process has established its IPC connection.
     93   // The |host| can be used when we need to send a message to it.
     94   void Connected(IPC::Sender* host);
     95   // Called when the remote process has closed its IPC connection.
     96   void Disconnected();
     97 
     98   // Called when we have a message from the remote process.
     99   bool OnMessageReceived(const IPC::Message& message);
    100 
    101   void HandleOpenFile(const base::string16& title,
    102                       const base::FilePath& default_path,
    103                       const base::string16& filter,
    104                       const OpenFileCompletion& on_success,
    105                       const FileSelectionCanceled& on_failure);
    106 
    107   void HandleOpenMultipleFiles(const base::string16& title,
    108                                const base::FilePath& default_path,
    109                                const base::string16& filter,
    110                                const OpenMultipleFilesCompletion& on_success,
    111                                const FileSelectionCanceled& on_failure);
    112 
    113   void HandleSaveFile(const base::string16& title,
    114                       const base::FilePath& default_path,
    115                       const base::string16& filter,
    116                       int filter_index,
    117                       const base::string16& default_extension,
    118                       const SaveFileCompletion& on_success,
    119                       const FileSelectionCanceled& on_failure);
    120 
    121   void HandleSelectFolder(const base::string16& title,
    122                           const SelectFolderCompletion& on_success,
    123                           const FileSelectionCanceled& on_failure);
    124 
    125   // Returns the active ASH root window.
    126   Window* GetAshWindow();
    127 
    128  private:
    129   explicit RemoteRootWindowHostWin(const gfx::Rect& bounds);
    130   virtual ~RemoteRootWindowHostWin();
    131 
    132   // IPC message handing methods:
    133   void OnMouseMoved(int32 x, int32 y, int32 flags);
    134   void OnMouseButton(int32 x,
    135                      int32 y,
    136                      int32 extra,
    137                      ui::EventType type,
    138                      ui::EventFlags flags);
    139   void OnKeyDown(uint32 vkey,
    140                  uint32 repeat_count,
    141                  uint32 scan_code,
    142                  uint32 flags);
    143   void OnKeyUp(uint32 vkey,
    144                uint32 repeat_count,
    145                uint32 scan_code,
    146                uint32 flags);
    147   void OnChar(uint32 key_code,
    148               uint32 repeat_count,
    149               uint32 scan_code,
    150               uint32 flags);
    151   void OnVisibilityChanged(bool visible);
    152   void OnTouchDown(int32 x, int32 y, uint64 timestamp, uint32 pointer_id);
    153   void OnTouchUp(int32 x, int32 y, uint64 timestamp, uint32 pointer_id);
    154   void OnTouchMoved(int32 x, int32 y, uint64 timestamp, uint32 pointer_id);
    155   void OnFileSaveAsDone(bool success,
    156                         const base::FilePath& filename,
    157                         int filter_index);
    158   void OnFileOpenDone(bool success, const base::FilePath& filename);
    159   void OnMultiFileOpenDone(bool success,
    160                            const std::vector<base::FilePath>& files);
    161   void OnSelectFolderDone(bool success, const base::FilePath& folder);
    162   void OnWindowActivated(bool active);
    163   void OnSetCursorPosAck();
    164   void OnWindowSizeChanged(uint32 width, uint32 height);
    165 
    166   // RootWindowHost overrides:
    167   virtual void SetDelegate(RootWindowHostDelegate* delegate) OVERRIDE;
    168   virtual RootWindow* GetRootWindow() OVERRIDE;
    169   virtual gfx::AcceleratedWidget GetAcceleratedWidget() OVERRIDE;
    170   virtual void Show() OVERRIDE;
    171   virtual void Hide() OVERRIDE;
    172   virtual void ToggleFullScreen() OVERRIDE;
    173   virtual gfx::Rect GetBounds() const OVERRIDE;
    174   virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE;
    175   virtual gfx::Insets GetInsets() const OVERRIDE;
    176   virtual void SetInsets(const gfx::Insets& insets) OVERRIDE;
    177   virtual gfx::Point GetLocationOnNativeScreen() const OVERRIDE;
    178   virtual void SetCapture() OVERRIDE;
    179   virtual void ReleaseCapture() OVERRIDE;
    180   virtual void SetCursor(gfx::NativeCursor cursor) OVERRIDE;
    181   virtual bool QueryMouseLocation(gfx::Point* location_return) OVERRIDE;
    182   virtual bool ConfineCursorToRootWindow() OVERRIDE;
    183   virtual void UnConfineCursor() OVERRIDE;
    184   virtual void OnCursorVisibilityChanged(bool show) OVERRIDE;
    185   virtual void MoveCursorTo(const gfx::Point& location) OVERRIDE;
    186   virtual void SetFocusWhenShown(bool focus_when_shown) OVERRIDE;
    187   virtual bool CopyAreaToSkCanvas(const gfx::Rect& source_bounds,
    188                                   const gfx::Point& dest_offset,
    189                                   SkCanvas* canvas) OVERRIDE;
    190   virtual void PostNativeEvent(const base::NativeEvent& native_event) OVERRIDE;
    191   virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE;
    192   virtual void PrepareForShutdown() OVERRIDE;
    193 
    194   // Helper function to dispatch a keyboard message to the desired target.
    195   // The default target is the RootWindowHostDelegate. For nested message loop
    196   // invocations we post a synthetic keyboard message directly into the message
    197   // loop. The dispatcher for the nested loop would then decide how this
    198   // message is routed.
    199   void DispatchKeyboardMessage(ui::EventType type,
    200                                uint32 vkey,
    201                                uint32 repeat_count,
    202                                uint32 scan_code,
    203                                uint32 flags,
    204                                bool is_character);
    205 
    206   RootWindowHostDelegate* delegate_;
    207   IPC::Sender* host_;
    208   scoped_ptr<ui::ViewProp> prop_;
    209 
    210   // Saved callbacks which inform the caller about the result of the open file/
    211   // save file/select operations.
    212   OpenFileCompletion file_open_completion_callback_;
    213   OpenMultipleFilesCompletion multi_file_open_completion_callback_;
    214   SaveFileCompletion file_saveas_completion_callback_;
    215   SelectFolderCompletion select_folder_completion_callback_;
    216   FileSelectionCanceled failure_callback_;
    217 
    218   // Set to true if we need to ignore mouse messages until the SetCursorPos
    219   // operation is acked by the viewer.
    220   bool ignore_mouse_moves_until_set_cursor_ack_;
    221 
    222   // Tracking last click event for synthetically generated mouse events.
    223   scoped_ptr<ui::MouseEvent> last_mouse_click_event_;
    224 
    225   DISALLOW_COPY_AND_ASSIGN(RemoteRootWindowHostWin);
    226 };
    227 
    228 }  // namespace aura
    229 
    230 #endif  // UI_AURA_REMOTE_ROOT_WINDOW_HOST_WIN_H_
    231