widget/windows/winrt/FrameworkView.cpp

Thu, 15 Jan 2015 15:59:08 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:59:08 +0100
branch
TOR_BUG_9701
changeset 10
ac0c01689b40
permissions
-rw-r--r--

Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #include "FrameworkView.h"
michael@0 7 #include "MetroAppShell.h"
michael@0 8 #include "MetroWidget.h"
michael@0 9 #include "mozilla/AutoRestore.h"
michael@0 10 #include "MetroUtils.h"
michael@0 11 #include "MetroApp.h"
michael@0 12 #include "UIABridgePublic.h"
michael@0 13 #include "KeyboardLayout.h"
michael@0 14
michael@0 15 // generated
michael@0 16 #include "UIABridge.h"
michael@0 17
michael@0 18 using namespace mozilla;
michael@0 19 using namespace mozilla::widget::winrt;
michael@0 20 #ifdef ACCESSIBILITY
michael@0 21 using namespace mozilla::a11y;
michael@0 22 #endif
michael@0 23 using namespace ABI::Windows::ApplicationModel;
michael@0 24 using namespace ABI::Windows::ApplicationModel::Core;
michael@0 25 using namespace ABI::Windows::ApplicationModel::Activation;
michael@0 26 using namespace ABI::Windows::UI::Core;
michael@0 27 using namespace ABI::Windows::UI::ViewManagement;
michael@0 28 using namespace ABI::Windows::UI::Input;
michael@0 29 using namespace ABI::Windows::Devices::Input;
michael@0 30 using namespace ABI::Windows::System;
michael@0 31 using namespace ABI::Windows::Foundation;
michael@0 32 using namespace Microsoft::WRL;
michael@0 33 using namespace Microsoft::WRL::Wrappers;
michael@0 34
michael@0 35 namespace mozilla {
michael@0 36 namespace widget {
michael@0 37 namespace winrt {
michael@0 38
michael@0 39 // statics
michael@0 40 bool FrameworkView::sKeyboardIsVisible = false;
michael@0 41 Rect FrameworkView::sKeyboardRect;
michael@0 42 HSTRING FrameworkView::sActivationURI = NULL;
michael@0 43 ApplicationExecutionState FrameworkView::sPreviousExecutionState;
michael@0 44 nsTArray<nsString>* sSettingsArray;
michael@0 45
michael@0 46 FrameworkView::FrameworkView(MetroApp* aMetroApp) :
michael@0 47 mDPI(-1.0f),
michael@0 48 mWidget(nullptr),
michael@0 49 mShuttingDown(false),
michael@0 50 mMetroApp(aMetroApp),
michael@0 51 mWindow(nullptr),
michael@0 52 mMetroInput(nullptr),
michael@0 53 mWinVisible(false),
michael@0 54 mWinActiveState(false)
michael@0 55 {
michael@0 56 mActivated.value = 0;
michael@0 57 mWindowActivated.value = 0;
michael@0 58 mWindowVisibilityChanged.value = 0;
michael@0 59 mWindowSizeChanged.value = 0;
michael@0 60 mSoftKeyboardHidden.value = 0;
michael@0 61 mSoftKeyboardShown.value = 0;
michael@0 62 mDisplayPropertiesChanged.value = 0;
michael@0 63 mAutomationProviderRequested.value = 0;
michael@0 64 mDataTransferRequested.value = 0;
michael@0 65 mSearchQuerySubmitted.value = 0;
michael@0 66 mPlayToRequested.value = 0;
michael@0 67 mSettingsPane.value = 0;
michael@0 68 mPrintManager.value = 0;
michael@0 69 memset(&sKeyboardRect, 0, sizeof(Rect));
michael@0 70 sSettingsArray = new nsTArray<nsString>();
michael@0 71 LogFunction();
michael@0 72 }
michael@0 73
michael@0 74 ////////////////////////////////////////////////////
michael@0 75 // IFrameworkView impl.
michael@0 76
michael@0 77 HRESULT
michael@0 78 FrameworkView::Initialize(ICoreApplicationView* aAppView)
michael@0 79 {
michael@0 80 LogFunction();
michael@0 81 if (mShuttingDown)
michael@0 82 return E_FAIL;
michael@0 83
michael@0 84 aAppView->add_Activated(Callback<__FITypedEventHandler_2_Windows__CApplicationModel__CCore__CCoreApplicationView_Windows__CApplicationModel__CActivation__CIActivatedEventArgs_t>(
michael@0 85 this, &FrameworkView::OnActivated).Get(), &mActivated);
michael@0 86
michael@0 87 //CoCreateInstance(CLSID_WICImagingFactory, nullptr,
michael@0 88 // CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&mWicFactory));
michael@0 89 return S_OK;
michael@0 90 }
michael@0 91
michael@0 92 HRESULT
michael@0 93 FrameworkView::Uninitialize()
michael@0 94 {
michael@0 95 return S_OK;
michael@0 96 }
michael@0 97
michael@0 98 HRESULT
michael@0 99 FrameworkView::Load(HSTRING aEntryPoint)
michael@0 100 {
michael@0 101 return S_OK;
michael@0 102 }
michael@0 103
michael@0 104 // called by winrt on startup
michael@0 105 HRESULT
michael@0 106 FrameworkView::Run()
michael@0 107 {
michael@0 108 LogFunction();
michael@0 109
michael@0 110 // Initialize XPCOM, create mWidget and go! We get a
michael@0 111 // callback in MetroAppShell::Run, in which we kick
michael@0 112 // off normal browser execution / event dispatching.
michael@0 113 mMetroApp->Run();
michael@0 114
michael@0 115 // Gecko is completely shut down at this point.
michael@0 116 WinUtils::Log("Exiting FrameworkView::Run()");
michael@0 117
michael@0 118 WindowsDeleteString(sActivationURI);
michael@0 119 return S_OK;
michael@0 120 }
michael@0 121
michael@0 122 HRESULT
michael@0 123 FrameworkView::ActivateView()
michael@0 124 {
michael@0 125 LogFunction();
michael@0 126
michael@0 127 UpdateWidgetSizeAndPosition();
michael@0 128
michael@0 129 nsIntRegion region(nsIntRect(0, 0, mWindowBounds.width, mWindowBounds.height));
michael@0 130 mWidget->Paint(region);
michael@0 131
michael@0 132 // Activate the window, this kills the splash screen
michael@0 133 mWindow->Activate();
michael@0 134
michael@0 135 ProcessLaunchArguments();
michael@0 136 AddEventHandlers();
michael@0 137 SetupContracts();
michael@0 138
michael@0 139 return S_OK;
michael@0 140 }
michael@0 141
michael@0 142 HRESULT
michael@0 143 FrameworkView::SetWindow(ICoreWindow* aWindow)
michael@0 144 {
michael@0 145 LogFunction();
michael@0 146
michael@0 147 NS_ASSERTION(!mWindow, "Attempting to set a window on a view that already has a window!");
michael@0 148 NS_ASSERTION(aWindow, "Attempting to set a null window on a view!");
michael@0 149
michael@0 150 mWindow = aWindow;
michael@0 151 UpdateLogicalDPI();
michael@0 152 return S_OK;
michael@0 153 }
michael@0 154
michael@0 155 ////////////////////////////////////////////////////
michael@0 156 // FrameworkView impl.
michael@0 157
michael@0 158 void
michael@0 159 FrameworkView::AddEventHandlers() {
michael@0 160 NS_ASSERTION(mWindow, "SetWindow must be called before AddEventHandlers!");
michael@0 161 NS_ASSERTION(mWidget, "SetWidget must be called before AddEventHAndlers!");
michael@0 162
michael@0 163 mMetroInput = Make<MetroInput>(mWidget.Get(),
michael@0 164 mWindow.Get());
michael@0 165
michael@0 166 mWindow->add_VisibilityChanged(Callback<__FITypedEventHandler_2_Windows__CUI__CCore__CCoreWindow_Windows__CUI__CCore__CVisibilityChangedEventArgs>(
michael@0 167 this, &FrameworkView::OnWindowVisibilityChanged).Get(), &mWindowVisibilityChanged);
michael@0 168 mWindow->add_Activated(Callback<__FITypedEventHandler_2_Windows__CUI__CCore__CCoreWindow_Windows__CUI__CCore__CWindowActivatedEventArgs_t>(
michael@0 169 this, &FrameworkView::OnWindowActivated).Get(), &mWindowActivated);
michael@0 170 mWindow->add_SizeChanged(Callback<__FITypedEventHandler_2_Windows__CUI__CCore__CCoreWindow_Windows__CUI__CCore__CWindowSizeChangedEventArgs_t>(
michael@0 171 this, &FrameworkView::OnWindowSizeChanged).Get(), &mWindowSizeChanged);
michael@0 172
michael@0 173 mWindow->add_AutomationProviderRequested(Callback<__FITypedEventHandler_2_Windows__CUI__CCore__CCoreWindow_Windows__CUI__CCore__CAutomationProviderRequestedEventArgs_t>(
michael@0 174 this, &FrameworkView::OnAutomationProviderRequested).Get(), &mAutomationProviderRequested);
michael@0 175
michael@0 176 HRESULT hr;
michael@0 177 ComPtr<ABI::Windows::Graphics::Display::IDisplayPropertiesStatics> dispProps;
michael@0 178 if (SUCCEEDED(GetActivationFactory(HStringReference(RuntimeClass_Windows_Graphics_Display_DisplayProperties).Get(), dispProps.GetAddressOf()))) {
michael@0 179 hr = dispProps->add_LogicalDpiChanged(Callback<ABI::Windows::Graphics::Display::IDisplayPropertiesEventHandler, FrameworkView>(
michael@0 180 this, &FrameworkView::OnLogicalDpiChanged).Get(), &mDisplayPropertiesChanged);
michael@0 181 LogHRESULT(hr);
michael@0 182 }
michael@0 183
michael@0 184 ComPtr<ABI::Windows::UI::ViewManagement::IInputPaneStatics> inputStatic;
michael@0 185 if (SUCCEEDED(hr = GetActivationFactory(HStringReference(RuntimeClass_Windows_UI_ViewManagement_InputPane).Get(), inputStatic.GetAddressOf()))) {
michael@0 186 ComPtr<ABI::Windows::UI::ViewManagement::IInputPane> inputPane;
michael@0 187 if (SUCCEEDED(inputStatic->GetForCurrentView(inputPane.GetAddressOf()))) {
michael@0 188 inputPane->add_Hiding(Callback<__FITypedEventHandler_2_Windows__CUI__CViewManagement__CInputPane_Windows__CUI__CViewManagement__CInputPaneVisibilityEventArgs_t>(
michael@0 189 this, &FrameworkView::OnSoftkeyboardHidden).Get(), &mSoftKeyboardHidden);
michael@0 190 inputPane->add_Showing(Callback<__FITypedEventHandler_2_Windows__CUI__CViewManagement__CInputPane_Windows__CUI__CViewManagement__CInputPaneVisibilityEventArgs_t>(
michael@0 191 this, &FrameworkView::OnSoftkeyboardShown).Get(), &mSoftKeyboardShown);
michael@0 192 }
michael@0 193 }
michael@0 194 }
michael@0 195
michael@0 196 // Called by MetroApp
michael@0 197 void
michael@0 198 FrameworkView::Shutdown()
michael@0 199 {
michael@0 200 LogFunction();
michael@0 201 mShuttingDown = true;
michael@0 202
michael@0 203 if (mWindow && mWindowVisibilityChanged.value) {
michael@0 204 mWindow->remove_VisibilityChanged(mWindowVisibilityChanged);
michael@0 205 mWindow->remove_Activated(mWindowActivated);
michael@0 206 mWindow->remove_Closed(mWindowClosed);
michael@0 207 mWindow->remove_SizeChanged(mWindowSizeChanged);
michael@0 208 mWindow->remove_AutomationProviderRequested(mAutomationProviderRequested);
michael@0 209 }
michael@0 210
michael@0 211 ComPtr<ABI::Windows::Graphics::Display::IDisplayPropertiesStatics> dispProps;
michael@0 212 if (mDisplayPropertiesChanged.value &&
michael@0 213 SUCCEEDED(GetActivationFactory(HStringReference(RuntimeClass_Windows_Graphics_Display_DisplayProperties).Get(), dispProps.GetAddressOf()))) {
michael@0 214 dispProps->remove_LogicalDpiChanged(mDisplayPropertiesChanged);
michael@0 215 }
michael@0 216
michael@0 217 ComPtr<ABI::Windows::UI::ViewManagement::IInputPaneStatics> inputStatic;
michael@0 218 if (mSoftKeyboardHidden.value &&
michael@0 219 SUCCEEDED(GetActivationFactory(HStringReference(RuntimeClass_Windows_UI_ViewManagement_InputPane).Get(), inputStatic.GetAddressOf()))) {
michael@0 220 ComPtr<ABI::Windows::UI::ViewManagement::IInputPane> inputPane;
michael@0 221 if (SUCCEEDED(inputStatic->GetForCurrentView(inputPane.GetAddressOf()))) {
michael@0 222 inputPane->remove_Hiding(mSoftKeyboardHidden);
michael@0 223 inputPane->remove_Showing(mSoftKeyboardShown);
michael@0 224 }
michael@0 225 }
michael@0 226
michael@0 227 if (mAutomationProvider) {
michael@0 228 ComPtr<IUIABridge> provider;
michael@0 229 mAutomationProvider.As(&provider);
michael@0 230 if (provider) {
michael@0 231 provider->Disconnect();
michael@0 232 }
michael@0 233 }
michael@0 234 mAutomationProvider = nullptr;
michael@0 235
michael@0 236 mMetroInput = nullptr;
michael@0 237 delete sSettingsArray;
michael@0 238 sSettingsArray = nullptr;
michael@0 239 mWidget = nullptr;
michael@0 240 mMetroApp = nullptr;
michael@0 241 mWindow = nullptr;
michael@0 242 }
michael@0 243
michael@0 244 void
michael@0 245 FrameworkView::SetCursor(CoreCursorType aCursorType, DWORD aCustomId)
michael@0 246 {
michael@0 247 if (mShuttingDown) {
michael@0 248 return;
michael@0 249 }
michael@0 250 NS_ASSERTION(mWindow, "SetWindow must be called before SetCursor!");
michael@0 251 ComPtr<ABI::Windows::UI::Core::ICoreCursorFactory> factory;
michael@0 252 AssertHRESULT(GetActivationFactory(HStringReference(RuntimeClass_Windows_UI_Core_CoreCursor).Get(), factory.GetAddressOf()));
michael@0 253 ComPtr<ABI::Windows::UI::Core::ICoreCursor> cursor;
michael@0 254 AssertHRESULT(factory->CreateCursor(aCursorType, aCustomId, cursor.GetAddressOf()));
michael@0 255 mWindow->put_PointerCursor(cursor.Get());
michael@0 256 }
michael@0 257
michael@0 258 void
michael@0 259 FrameworkView::ClearCursor()
michael@0 260 {
michael@0 261 if (mShuttingDown) {
michael@0 262 return;
michael@0 263 }
michael@0 264 NS_ASSERTION(mWindow, "SetWindow must be called before ClearCursor!");
michael@0 265 mWindow->put_PointerCursor(nullptr);
michael@0 266 }
michael@0 267
michael@0 268 void
michael@0 269 FrameworkView::UpdateLogicalDPI()
michael@0 270 {
michael@0 271 ComPtr<ABI::Windows::Graphics::Display::IDisplayPropertiesStatics> dispProps;
michael@0 272 HRESULT hr = GetActivationFactory(HStringReference(RuntimeClass_Windows_Graphics_Display_DisplayProperties).Get(),
michael@0 273 dispProps.GetAddressOf());
michael@0 274 AssertHRESULT(hr);
michael@0 275 FLOAT value;
michael@0 276 AssertHRESULT(dispProps->get_LogicalDpi(&value));
michael@0 277 SetDpi(value);
michael@0 278 }
michael@0 279
michael@0 280 void
michael@0 281 FrameworkView::GetBounds(nsIntRect &aRect)
michael@0 282 {
michael@0 283 // May be called by compositor thread
michael@0 284 if (mShuttingDown) {
michael@0 285 return;
michael@0 286 }
michael@0 287 aRect = mWindowBounds;
michael@0 288 }
michael@0 289
michael@0 290 void
michael@0 291 FrameworkView::UpdateWidgetSizeAndPosition()
michael@0 292 {
michael@0 293 if (mShuttingDown)
michael@0 294 return;
michael@0 295
michael@0 296 NS_ASSERTION(mWindow, "SetWindow must be called before UpdateWidgetSizeAndPosition!");
michael@0 297 NS_ASSERTION(mWidget, "SetWidget must be called before UpdateWidgetSizeAndPosition!");
michael@0 298
michael@0 299 UpdateBounds();
michael@0 300 mWidget->Move(0, 0);
michael@0 301 mWidget->Resize(0, 0, mWindowBounds.width, mWindowBounds.height, true);
michael@0 302 mWidget->SizeModeChanged();
michael@0 303 }
michael@0 304
michael@0 305 bool
michael@0 306 FrameworkView::IsEnabled() const
michael@0 307 {
michael@0 308 return mWinActiveState;
michael@0 309 }
michael@0 310
michael@0 311 bool
michael@0 312 FrameworkView::IsVisible() const
michael@0 313 {
michael@0 314 // we could check the wnd in MetroWidget for this, but
michael@0 315 // generally we don't let nsIWidget control visibility
michael@0 316 // or activation.
michael@0 317 return mWinVisible;
michael@0 318 }
michael@0 319
michael@0 320 void FrameworkView::SetDpi(float aDpi)
michael@0 321 {
michael@0 322 if (aDpi != mDPI) {
michael@0 323 LogFunction();
michael@0 324
michael@0 325 mDPI = aDpi;
michael@0 326
michael@0 327 // notify the widget that dpi has changed
michael@0 328 if (mWidget) {
michael@0 329 mWidget->ChangedDPI();
michael@0 330 UpdateBounds();
michael@0 331 }
michael@0 332 }
michael@0 333 }
michael@0 334
michael@0 335 void
michael@0 336 FrameworkView::UpdateBounds()
michael@0 337 {
michael@0 338 if (!mWidget)
michael@0 339 return;
michael@0 340
michael@0 341 RECT winRect;
michael@0 342 GetClientRect(mWidget->GetICoreWindowHWND(), &winRect);
michael@0 343
michael@0 344 mWindowBounds = nsIntRect(winRect.left,
michael@0 345 winRect.top,
michael@0 346 winRect.right - winRect.left,
michael@0 347 winRect.bottom - winRect.top);
michael@0 348 }
michael@0 349
michael@0 350 void
michael@0 351 FrameworkView::SetWidget(MetroWidget* aWidget)
michael@0 352 {
michael@0 353 NS_ASSERTION(!mWidget, "Attempting to set a widget for a view that already has a widget!");
michael@0 354 NS_ASSERTION(aWidget, "Attempting to set a null widget for a view!");
michael@0 355 LogFunction();
michael@0 356 mWidget = aWidget;
michael@0 357 mWidget->FindMetroWindow();
michael@0 358 UpdateBounds();
michael@0 359 }
michael@0 360
michael@0 361 ////////////////////////////////////////////////////
michael@0 362 // Event handlers
michael@0 363
michael@0 364 void
michael@0 365 FrameworkView::SendActivationEvent()
michael@0 366 {
michael@0 367 if (mShuttingDown) {
michael@0 368 return;
michael@0 369 }
michael@0 370 NS_ASSERTION(mWindow, "SetWindow must be called before SendActivationEvent!");
michael@0 371 mWidget->Activated(mWinActiveState);
michael@0 372 if (mWinActiveState) {
michael@0 373 UpdateWidgetSizeAndPosition();
michael@0 374 }
michael@0 375 EnsureAutomationProviderCreated();
michael@0 376 }
michael@0 377
michael@0 378 HRESULT
michael@0 379 FrameworkView::OnWindowVisibilityChanged(ICoreWindow* aWindow,
michael@0 380 IVisibilityChangedEventArgs* aArgs)
michael@0 381 {
michael@0 382 // If we're visible, or we can't determine if we're visible, just store
michael@0 383 // that we are visible.
michael@0 384 boolean visible;
michael@0 385 mWinVisible = FAILED(aArgs->get_Visible(&visible)) || visible;
michael@0 386 return S_OK;
michael@0 387 }
michael@0 388
michael@0 389 HRESULT
michael@0 390 FrameworkView::OnActivated(ICoreApplicationView* aApplicationView,
michael@0 391 IActivatedEventArgs* aArgs)
michael@0 392 {
michael@0 393 LogFunction();
michael@0 394
michael@0 395 if (mShuttingDown) {
michael@0 396 return S_OK;
michael@0 397 }
michael@0 398
michael@0 399 aArgs->get_PreviousExecutionState(&sPreviousExecutionState);
michael@0 400 bool startup = sPreviousExecutionState == ApplicationExecutionState::ApplicationExecutionState_Terminated ||
michael@0 401 sPreviousExecutionState == ApplicationExecutionState::ApplicationExecutionState_ClosedByUser ||
michael@0 402 sPreviousExecutionState == ApplicationExecutionState::ApplicationExecutionState_NotRunning;
michael@0 403 ProcessActivationArgs(aArgs, startup);
michael@0 404 return S_OK;
michael@0 405 }
michael@0 406
michael@0 407 HRESULT
michael@0 408 FrameworkView::OnSoftkeyboardHidden(IInputPane* aSender,
michael@0 409 IInputPaneVisibilityEventArgs* aArgs)
michael@0 410 {
michael@0 411 LogFunction();
michael@0 412 sKeyboardIsVisible = false;
michael@0 413 memset(&sKeyboardRect, 0, sizeof(Rect));
michael@0 414 MetroUtils::FireObserver("metro_softkeyboard_hidden");
michael@0 415 aArgs->put_EnsuredFocusedElementInView(true);
michael@0 416 return S_OK;
michael@0 417 }
michael@0 418
michael@0 419 HRESULT
michael@0 420 FrameworkView::OnSoftkeyboardShown(IInputPane* aSender,
michael@0 421 IInputPaneVisibilityEventArgs* aArgs)
michael@0 422 {
michael@0 423 LogFunction();
michael@0 424 sKeyboardIsVisible = true;
michael@0 425 aSender->get_OccludedRect(&sKeyboardRect);
michael@0 426 MetroUtils::FireObserver("metro_softkeyboard_shown");
michael@0 427 aArgs->put_EnsuredFocusedElementInView(true);
michael@0 428 return S_OK;
michael@0 429 }
michael@0 430
michael@0 431 HRESULT
michael@0 432 FrameworkView::OnWindowSizeChanged(ICoreWindow* aSender, IWindowSizeChangedEventArgs* aArgs)
michael@0 433 {
michael@0 434 LogFunction();
michael@0 435 UpdateWidgetSizeAndPosition();
michael@0 436 return S_OK;
michael@0 437 }
michael@0 438
michael@0 439 HRESULT
michael@0 440 FrameworkView::OnWindowActivated(ICoreWindow* aSender, IWindowActivatedEventArgs* aArgs)
michael@0 441 {
michael@0 442 LogFunction();
michael@0 443 if (!mWidget) {
michael@0 444 return S_OK;
michael@0 445 }
michael@0 446 CoreWindowActivationState state;
michael@0 447 aArgs->get_WindowActivationState(&state);
michael@0 448 mWinActiveState = !(state == CoreWindowActivationState::CoreWindowActivationState_Deactivated);
michael@0 449 SendActivationEvent();
michael@0 450 return S_OK;
michael@0 451 }
michael@0 452
michael@0 453 HRESULT
michael@0 454 FrameworkView::OnLogicalDpiChanged(IInspectable* aSender)
michael@0 455 {
michael@0 456 LogFunction();
michael@0 457 UpdateLogicalDPI();
michael@0 458 if (mWidget) {
michael@0 459 mWidget->Invalidate();
michael@0 460 }
michael@0 461 return S_OK;
michael@0 462 }
michael@0 463
michael@0 464 bool
michael@0 465 FrameworkView::EnsureAutomationProviderCreated()
michael@0 466 {
michael@0 467 #ifdef ACCESSIBILITY
michael@0 468 if (!mWidget || mShuttingDown)
michael@0 469 return false;
michael@0 470
michael@0 471 if (mAutomationProvider) {
michael@0 472 return true;
michael@0 473 }
michael@0 474
michael@0 475 Accessible *rootAccessible = mWidget->GetRootAccessible();
michael@0 476 if (rootAccessible) {
michael@0 477 IInspectable* inspectable;
michael@0 478 HRESULT hr;
michael@0 479 AssertRetHRESULT(hr = UIABridge_CreateInstance(&inspectable), hr); // Addref
michael@0 480 IUIABridge* bridge = nullptr;
michael@0 481 inspectable->QueryInterface(IID_IUIABridge, (void**)&bridge); // Addref
michael@0 482 if (bridge) {
michael@0 483 bridge->Init(this, mWindow.Get(), (ULONG)rootAccessible);
michael@0 484 mAutomationProvider = inspectable;
michael@0 485 inspectable->Release();
michael@0 486 return true;
michael@0 487 }
michael@0 488 }
michael@0 489 #endif
michael@0 490 return false;
michael@0 491 }
michael@0 492
michael@0 493 HRESULT
michael@0 494 FrameworkView::OnAutomationProviderRequested(ICoreWindow* aSender,
michael@0 495 IAutomationProviderRequestedEventArgs* aArgs)
michael@0 496 {
michael@0 497 LogFunction();
michael@0 498 if (!EnsureAutomationProviderCreated())
michael@0 499 return E_FAIL;
michael@0 500 HRESULT hr = aArgs->put_AutomationProvider(mAutomationProvider.Get());
michael@0 501 if (FAILED(hr)) {
michael@0 502 WinUtils::Log("put failed? %X", hr);
michael@0 503 }
michael@0 504 return S_OK;
michael@0 505 }
michael@0 506
michael@0 507 } } }

mercurial