OLD | NEW |
(Empty) | |
| 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 CHROME_BROWSER_UI_METRO_DRIVER_CHROME_APP_VIEW_H_ |
| 6 #define CHROME_BROWSER_UI_METRO_DRIVER_CHROME_APP_VIEW_H_ |
| 7 |
| 8 #include <windows.applicationmodel.core.h> |
| 9 #include <windows.ui.core.h> |
| 10 #include <windows.ui.input.h> |
| 11 #include <windows.ui.viewmanagement.h> |
| 12 |
| 13 #include <list> |
| 14 #include <map> |
| 15 #include <string> |
| 16 #include <utility> |
| 17 |
| 18 #include "base/memory/scoped_ptr.h" |
| 19 #include "base/message_loop.h" |
| 20 #include "base/synchronization/lock.h" |
| 21 #include "win8/metro_driver/chrome_url_launch_handler.h" |
| 22 #include "win8/metro_driver/devices_handler.h" |
| 23 #include "win8/metro_driver/metro_dialog_box.h" |
| 24 #include "win8/metro_driver/settings_handler.h" |
| 25 #include "win8/metro_driver/toast_notification_handler.h" |
| 26 |
| 27 class ChromeAppView |
| 28 : public mswr::RuntimeClass<winapp::Core::IFrameworkView> { |
| 29 public: |
| 30 ChromeAppView(); |
| 31 ~ChromeAppView(); |
| 32 |
| 33 // IViewProvider overrides. |
| 34 IFACEMETHOD(Initialize)(winapp::Core::ICoreApplicationView* view); |
| 35 IFACEMETHOD(SetWindow)(winui::Core::ICoreWindow* window); |
| 36 IFACEMETHOD(Load)(HSTRING entryPoint); |
| 37 IFACEMETHOD(Run)(); |
| 38 IFACEMETHOD(Uninitialize)(); |
| 39 |
| 40 static LRESULT CALLBACK CoreWindowProc(HWND window, UINT message, WPARAM wp, |
| 41 LPARAM lp); |
| 42 |
| 43 HRESULT TileRequestCreateDone(winfoundtn::IAsyncOperation<bool>* async, |
| 44 AsyncStatus status); |
| 45 |
| 46 bool osk_visible_notification_received() const { |
| 47 return osk_visible_notification_received_; |
| 48 } |
| 49 |
| 50 // Displays the notification. |
| 51 void DisplayNotification( |
| 52 const ToastNotificationHandler::DesktopNotification& notification); |
| 53 |
| 54 // Cancels the notification. |
| 55 void CancelNotification(const std::string& notification); |
| 56 |
| 57 // Returns true if the notification passed in is valid. |
| 58 bool IsValidNotification(const std::string& notification); |
| 59 |
| 60 // Displays a dialog box. |
| 61 void ShowDialogBox(const MetroDialogBox::DialogBoxInfo& dialog_box_info); |
| 62 // Dismisses the dialog box. |
| 63 void DismissDialogBox(); |
| 64 |
| 65 // Helper function to unsnap the chrome metro app if it is snapped. |
| 66 // Returns S_OK on success. |
| 67 static HRESULT Unsnap(); |
| 68 |
| 69 // Notification from chrome that a full screen operation is being performed. |
| 70 void SetFullscreen(bool fullscreen); |
| 71 |
| 72 private: |
| 73 HRESULT OnActivate(winapp::Core::ICoreApplicationView* view, |
| 74 winapp::Activation::IActivatedEventArgs* args); |
| 75 |
| 76 HRESULT OnSizeChanged(winui::Core::ICoreWindow* sender, |
| 77 winui::Core::IWindowSizeChangedEventArgs* args); |
| 78 |
| 79 HRESULT OnEdgeGestureCompleted(winui::Input::IEdgeGesture* gesture, |
| 80 winui::Input::IEdgeGestureEventArgs* args); |
| 81 |
| 82 HRESULT OnShareDataRequested( |
| 83 winapp::DataTransfer::IDataTransferManager* data_transfer_mgr, |
| 84 winapp::DataTransfer::IDataRequestedEventArgs* event_args); |
| 85 |
| 86 HRESULT OnInputPaneVisible( |
| 87 winui::ViewManagement::IInputPane* input_pane, |
| 88 winui::ViewManagement::IInputPaneVisibilityEventArgs* event_args); |
| 89 |
| 90 HRESULT OnInputPaneHiding( |
| 91 winui::ViewManagement::IInputPane* input_pane, |
| 92 winui::ViewManagement::IInputPaneVisibilityEventArgs* event_args); |
| 93 |
| 94 HRESULT OnPositionChanged(int x, int y); |
| 95 |
| 96 void CheckForOSKActivation(); |
| 97 |
| 98 HRESULT RegisterInputPaneNotifications(); |
| 99 |
| 100 void HandleInputPaneVisible(const RECT& osk_rect); |
| 101 void HandleInputPaneHidden(const RECT& osk_rect); |
| 102 |
| 103 mswr::ComPtr<winui::Core::ICoreWindow> window_; |
| 104 mswr::ComPtr<winapp::Core::ICoreApplicationView> view_; |
| 105 EventRegistrationToken activated_token_; |
| 106 EventRegistrationToken edgeevent_token_; |
| 107 EventRegistrationToken sizechange_token_; |
| 108 EventRegistrationToken share_data_requested_token_; |
| 109 EventRegistrationToken input_pane_visible_token_; |
| 110 EventRegistrationToken input_pane_hiding_token_; |
| 111 EventRegistrationToken app_exit_token_; |
| 112 |
| 113 ChromeUrlLaunchHandler url_launch_handler_; |
| 114 metro_driver::DevicesHandler devices_handler_; |
| 115 SettingsHandler settings_handler_; |
| 116 mswr::ComPtr<winui::ViewManagement::IInputPane> input_pane_; |
| 117 mswr::ComPtr<winui::ViewManagement::IApplicationViewStatics> app_view_; |
| 118 |
| 119 bool osk_visible_notification_received_; |
| 120 |
| 121 // map of notification id to the ToastNotificationHandler instance. |
| 122 typedef std::map<std::string, scoped_ptr<ToastNotificationHandler> > |
| 123 NotificationMap; |
| 124 NotificationMap notification_map_; |
| 125 |
| 126 // Synchronizes access to the notification_map_ member. |
| 127 base::Lock notification_lock_; |
| 128 |
| 129 // If the OSK covers the input area we scroll the window by the height of the |
| 130 // OSK + an additional offset. This member holds this offset. Set to 0 if the |
| 131 // window was not scrolled. |
| 132 int osk_offset_adjustment_; |
| 133 |
| 134 MetroDialogBox dialog_box_; |
| 135 }; |
| 136 |
| 137 class ChromeAppViewFactory |
| 138 : public mswr::RuntimeClass<winapp::Core::IFrameworkViewSource> { |
| 139 public: |
| 140 ChromeAppViewFactory(winapp::Core::ICoreApplication* icore_app, |
| 141 LPTHREAD_START_ROUTINE host_main, |
| 142 void* host_context); |
| 143 IFACEMETHOD(CreateView)(winapp::Core::IFrameworkView** view); |
| 144 }; |
| 145 |
| 146 // This function is exported by chrome.exe. |
| 147 typedef int (__cdecl *BreakpadExceptionHandler)(EXCEPTION_POINTERS* info); |
| 148 |
| 149 // Global information used across the metro driver. |
| 150 struct Globals { |
| 151 LPTHREAD_START_ROUTINE host_main; |
| 152 void* host_context; |
| 153 HWND core_window; |
| 154 // The pair below contains the HWND and a bool which indicates whether the |
| 155 // window was displaced to ensure that the focused region is visible when |
| 156 // the OSK is displayed. |
| 157 std::list<std::pair<HWND, bool> > host_windows; |
| 158 HANDLE host_thread; |
| 159 DWORD main_thread_id; |
| 160 ChromeAppView* view; |
| 161 WNDPROC g_core_proc; |
| 162 string16 navigation_url; |
| 163 string16 search_string; |
| 164 winapp::Activation::ApplicationExecutionState previous_state; |
| 165 winapp::Activation::ActivationKind initial_activation_kind; |
| 166 bool is_initial_activation; |
| 167 // This message loop lives in the app view's thread. Some operations have |
| 168 // to be initiated from that thread, notably spawning file pickers. |
| 169 base::MessageLoopProxy* appview_msg_loop; |
| 170 winapp::Core::ICoreApplicationExit* app_exit; |
| 171 BreakpadExceptionHandler breakpad_exception_handler; |
| 172 string16 metro_command_line_switches; |
| 173 }; |
| 174 |
| 175 extern Globals globals; |
| 176 |
| 177 #endif // CHROME_BROWSER_UI_METRO_DRIVER_CHROME_APP_VIEW_H_ |
OLD | NEW |