void FrameworkView::PerformSearch(HString& aQuery) { LogFunction(); nsCOMPtr<nsICommandLineRunner> cmdLine = (do_CreateInstance("@mozilla.org/toolkit/command-line;1")); if (!cmdLine) { NS_WARNING("Unable to instantiate command line runner."); return; } nsAutoCString parameter; parameter.Append('"'); unsigned int length; parameter.Append(NS_ConvertUTF16toUTF8(aQuery.GetRawBuffer(&length))); parameter.Append('"'); // NB: The first argument gets stripped by nsICommandLineRunner::Init, // so it doesn't matter what we pass as the first argument, but we // have to pass something. const char *argv[] = { "", // This argument gets stripped "-search", parameter.BeginReading() }; nsresult rv = cmdLine->Init(ArrayLength(argv), const_cast<char **>(argv), nullptr, nsICommandLine::STATE_REMOTE_EXPLICIT); if (NS_FAILED(rv)) { NS_WARNING("cmdLine->Init failed."); return; } cmdLine->Run(); }
HRESULT FrameworkView::OnWindowSizeChanged(ICoreWindow* aSender, IWindowSizeChangedEventArgs* aArgs) { LogFunction(); UpdateWidgetSizeAndPosition(); return S_OK; }
FrameworkView::FrameworkView(MetroApp* aMetroApp) : mDPI(-1.0f), mWidget(nullptr), mShuttingDown(false), mMetroApp(aMetroApp), mWindow(nullptr), mMetroInput(nullptr), mWinVisible(false), mWinActiveState(false) { mActivated.value = 0; mWindowActivated.value = 0; mWindowVisibilityChanged.value = 0; mWindowSizeChanged.value = 0; mSoftKeyboardHidden.value = 0; mSoftKeyboardShown.value = 0; mDisplayPropertiesChanged.value = 0; mAutomationProviderRequested.value = 0; mDataTransferRequested.value = 0; mSearchQuerySubmitted.value = 0; mPlayToRequested.value = 0; mSettingsPane.value = 0; mPrintManager.value = 0; memset(&sKeyboardRect, 0, sizeof(Rect)); sSettingsArray = new nsTArray<nsString>(); LogFunction(); }
void FrameworkView::SetWidget(MetroWidget* aWidget) { NS_ASSERTION(!mWidget, "Attempting to set a widget for a view that already has a widget!"); NS_ASSERTION(aWidget, "Attempting to set a null widget for a view!"); LogFunction(); mWidget = aWidget; mWidget->FindMetroWindow(); }
void FrameworkView::SetupContracts() { LogFunction(); HRESULT hr; // Add support for the share charm to indicate that we share data to other apps ComPtr<IDataTransferManagerStatics> transStatics; hr = GetActivationFactory(HStringReference(RuntimeClass_Windows_ApplicationModel_DataTransfer_DataTransferManager).Get(), transStatics.GetAddressOf()); AssertHRESULT(hr); ComPtr<IDataTransferManager> trans; AssertHRESULT(transStatics->GetForCurrentView(trans.GetAddressOf())); trans->add_DataRequested(Callback<__FITypedEventHandler_2_Windows__CApplicationModel__CDataTransfer__CDataTransferManager_Windows__CApplicationModel__CDataTransfer__CDataRequestedEventArgs_t>( this, &FrameworkView::OnDataShareRequested).Get(), &mDataTransferRequested); // Add support for the search charm to indicate that you can search using our app. ComPtr<ISearchPaneStatics> searchStatics; hr = GetActivationFactory(HStringReference(RuntimeClass_Windows_ApplicationModel_Search_SearchPane).Get(), searchStatics.GetAddressOf()); AssertHRESULT(hr); ComPtr<ISearchPane> searchPane; AssertHRESULT(searchStatics->GetForCurrentView(searchPane.GetAddressOf())); searchPane->add_QuerySubmitted(Callback<__FITypedEventHandler_2_Windows__CApplicationModel__CSearch__CSearchPane_Windows__CApplicationModel__CSearch__CSearchPaneQuerySubmittedEventArgs_t>( this, &FrameworkView::OnSearchQuerySubmitted).Get(), &mSearchQuerySubmitted); // Add support for the devices play to charm ComPtr<IPlayToManagerStatics> playToStatics; hr = GetActivationFactory(HStringReference(RuntimeClass_Windows_Media_PlayTo_PlayToManager).Get(), playToStatics.GetAddressOf()); AssertHRESULT(hr); ComPtr<IPlayToManager> playTo; AssertHRESULT(playToStatics->GetForCurrentView(playTo.GetAddressOf())); playTo->add_SourceRequested(Callback<__FITypedEventHandler_2_Windows__CMedia__CPlayTo__CPlayToManager_Windows__CMedia__CPlayTo__CPlayToSourceRequestedEventArgs_t>( this, &FrameworkView::OnPlayToSourceRequested).Get(), &mPlayToRequested); // Add support for the settings charm ComPtr<ISettingsPaneStatics> settingsPaneStatics; hr = GetActivationFactory(HStringReference(RuntimeClass_Windows_UI_ApplicationSettings_SettingsPane).Get(), settingsPaneStatics.GetAddressOf()); AssertHRESULT(hr); ComPtr<ISettingsPane> settingsPane; AssertHRESULT(settingsPaneStatics->GetForCurrentView(settingsPane.GetAddressOf())); settingsPane->add_CommandsRequested(Callback<__FITypedEventHandler_2_Windows__CUI__CApplicationSettings__CSettingsPane_Windows__CUI__CApplicationSettings__CSettingsPaneCommandsRequestedEventArgs_t>( this, &FrameworkView::OnSettingsCommandsRequested).Get(), &mSettingsPane); // Add support for the settings print charm ComPtr<IPrintManagerStatic> printStatics; hr = GetActivationFactory(HStringReference(RuntimeClass_Windows_Graphics_Printing_PrintManager).Get(), printStatics.GetAddressOf()); AssertHRESULT(hr); ComPtr<IPrintManager> printManager; AssertHRESULT(printStatics->GetForCurrentView(printManager.GetAddressOf())); printManager->add_PrintTaskRequested(Callback<__FITypedEventHandler_2_Windows__CGraphics__CPrinting__CPrintManager_Windows__CGraphics__CPrinting__CPrintTaskRequestedEventArgs_t>( this, &FrameworkView::OnPrintTaskRequested).Get(), &mPrintManager); }
HRESULT FrameworkView::OnSearchQuerySubmitted(ISearchPane* aPane, ISearchPaneQuerySubmittedEventArgs* aArgs) { LogFunction(); HString aQuery; aArgs->get_QueryText(aQuery.GetAddressOf()); PerformURILoadOrSearch(aQuery); return S_OK; }
HRESULT FrameworkView::OnLogicalDpiChanged(IInspectable* aSender) { LogFunction(); UpdateLogicalDPI(); if (mWidget) { mWidget->Invalidate(); } return S_OK; }
HRESULT FrameworkView::OnSoftkeyboardHidden(IInputPane* aSender, IInputPaneVisibilityEventArgs* aArgs) { LogFunction(); sKeyboardIsVisible = false; memset(&sKeyboardRect, 0, sizeof(Rect)); MetroUtils::FireObserver("metro_softkeyboard_hidden"); aArgs->put_EnsuredFocusedElementInView(true); return S_OK; }
HRESULT FrameworkView::OnSoftkeyboardShown(IInputPane* aSender, IInputPaneVisibilityEventArgs* aArgs) { LogFunction(); sKeyboardIsVisible = true; aSender->get_OccludedRect(&sKeyboardRect); MetroUtils::FireObserver("metro_softkeyboard_shown"); aArgs->put_EnsuredFocusedElementInView(true); return S_OK; }
HRESULT FrameworkView::OnWindowActivated(ICoreWindow* aSender, IWindowActivatedEventArgs* aArgs) { LogFunction(); if (mShuttingDown || !mWidget) return E_FAIL; CoreWindowActivationState state; aArgs->get_WindowActivationState(&state); mWinActiveState = !(state == CoreWindowActivationState::CoreWindowActivationState_Deactivated); SendActivationEvent(); return S_OK; }
// Called after CoreApplication::Run(app) HRESULT MetroApp::CreateView(ABI::Windows::ApplicationModel::Core::IFrameworkView **aViewProvider) { // This entry point is called on the metro main thread, but the thread won't be // recognized as such until after Initialize is called below. XPCOM has not gone // through startup at this point. LogFunction(); *aViewProvider = sFrameworkView.Get(); return !sFrameworkView ? E_FAIL : S_OK; }
HRESULT FrameworkView::SetWindow(ICoreWindow* aWindow) { LogFunction(); NS_ASSERTION(!mWindow, "Attempting to set a window on a view that already has a window!"); NS_ASSERTION(aWindow, "Attempting to set a null window on a view!"); mWindow = aWindow; UpdateLogicalDPI(); return S_OK; }
// Request a shutdown of the application void MetroApp::CoreExit() { LogFunction(); HRESULT hr; ComPtr<ICoreApplicationExit> coreExit; HStringReference className(RuntimeClass_Windows_ApplicationModel_Core_CoreApplication); hr = GetActivationFactory(className.Get(), coreExit.GetAddressOf()); NS_ASSERTION(SUCCEEDED(hr), "Activation of ICoreApplicationExit"); if (SUCCEEDED(hr)) { coreExit->Exit(); } }
HRESULT FrameworkView::OnAutomationProviderRequested(ICoreWindow* aSender, IAutomationProviderRequestedEventArgs* aArgs) { LogFunction(); if (!EnsureAutomationProviderCreated()) return E_FAIL; HRESULT hr = aArgs->put_AutomationProvider(mAutomationProvider.Get()); if (FAILED(hr)) { WinUtils::Log("put failed? %X", hr); } return S_OK; }
bool DoStateCheck(ConEmuStateCheck eStateCheck) { LogFunction(L"DoStateCheck"); bool bOn = false; switch (eStateCheck) { case ec_IsConEmu: case ec_IsAnsi: if (ghConWnd) { CESERVER_CONSOLE_MAPPING_HDR* pInfo = (CESERVER_CONSOLE_MAPPING_HDR*)malloc(sizeof(*pInfo)); if (pInfo && LoadSrvMapping(ghConWnd, *pInfo)) { _ASSERTE(pInfo->ComSpec.ConEmuExeDir[0] && pInfo->ComSpec.ConEmuBaseDir[0]); HWND hWnd = pInfo->hConEmuWndDc; if (hWnd && IsWindow(hWnd)) { switch (eStateCheck) { case ec_IsConEmu: bOn = true; break; case ec_IsAnsi: bOn = ((pInfo->Flags & CECF_ProcessAnsi) != 0); break; default: ; } } } SafeFree(pInfo); } break; case ec_IsAdmin: bOn = IsUserAdmin(); break; case ec_IsRedirect: bOn = IsOutputRedirected(); break; case ec_IsTerm: bOn = isTerminalMode(); break; default: _ASSERTE(FALSE && "Unsupported StateCheck code"); } return bOn; }
FrameworkView::FrameworkView(MetroApp* aMetroApp) : mDPI(-1.0f), mWidget(nullptr), mShuttingDown(false), mMetroApp(aMetroApp), mWindow(nullptr), mMetroInput(nullptr), mWinVisible(false), mWinActiveState(false) { memset(&sKeyboardRect, 0, sizeof(Rect)); sSettingsArray = new nsTArray<nsString>(); LogFunction(); }
HRESULT FrameworkView::OnActivated(ICoreApplicationView* aApplicationView, IActivatedEventArgs* aArgs) { LogFunction(); ApplicationExecutionState state; aArgs->get_PreviousExecutionState(&state); bool startup = state == ApplicationExecutionState::ApplicationExecutionState_Terminated || state == ApplicationExecutionState::ApplicationExecutionState_ClosedByUser || state == ApplicationExecutionState::ApplicationExecutionState_NotRunning; ProcessActivationArgs(aArgs, startup); return S_OK; }
void FrameworkView::SetDpi(float aDpi) { if (aDpi != mDPI) { LogFunction(); mDPI = aDpi; // notify the widget that dpi has changed if (mWidget) { mWidget->ChangedDPI(); UpdateBounds(); } } }
HRESULT FrameworkView::Initialize(ICoreApplicationView* aAppView) { LogFunction(); if (mShuttingDown) return E_FAIL; aAppView->add_Activated(Callback<__FITypedEventHandler_2_Windows__CApplicationModel__CCore__CCoreApplicationView_Windows__CApplicationModel__CActivation__CIActivatedEventArgs_t>( this, &FrameworkView::OnActivated).Get(), &mActivated); //CoCreateInstance(CLSID_WICImagingFactory, nullptr, // CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&mWicFactory)); return S_OK; }
// called by winrt on startup HRESULT FrameworkView::Run() { LogFunction(); // Initialize XPCOM, create mWidget and go! We get a // callback in MetroAppShell::Run, in which we kick // off normal browser execution / event dispatching. mMetroApp->Run(); // Gecko is completely shut down at this point. Log("Exiting FrameworkView::Run()"); return S_OK; }
// Called by MetroApp void FrameworkView::Shutdown() { LogFunction(); mShuttingDown = true; if (mWindow && mWindowVisibilityChanged.value) { mWindow->remove_VisibilityChanged(mWindowVisibilityChanged); mWindow->remove_Activated(mWindowActivated); mWindow->remove_Closed(mWindowClosed); mWindow->remove_SizeChanged(mWindowSizeChanged); mWindow->remove_AutomationProviderRequested(mAutomationProviderRequested); } ComPtr<ABI::Windows::Graphics::Display::IDisplayPropertiesStatics> dispProps; if (mDisplayPropertiesChanged.value && SUCCEEDED(GetActivationFactory(HStringReference(RuntimeClass_Windows_Graphics_Display_DisplayProperties).Get(), dispProps.GetAddressOf()))) { dispProps->remove_LogicalDpiChanged(mDisplayPropertiesChanged); } ComPtr<ABI::Windows::UI::ViewManagement::IInputPaneStatics> inputStatic; if (mSoftKeyboardHidden.value && SUCCEEDED(GetActivationFactory(HStringReference(RuntimeClass_Windows_UI_ViewManagement_InputPane).Get(), inputStatic.GetAddressOf()))) { ComPtr<ABI::Windows::UI::ViewManagement::IInputPane> inputPane; if (SUCCEEDED(inputStatic->GetForCurrentView(inputPane.GetAddressOf()))) { inputPane->remove_Hiding(mSoftKeyboardHidden); inputPane->remove_Showing(mSoftKeyboardShown); } } if (mAutomationProvider) { ComPtr<IUIABridge> provider; mAutomationProvider.As(&provider); if (provider) { provider->Disconnect(); } } mAutomationProvider = nullptr; mMetroInput = nullptr; delete sSettingsArray; sSettingsArray = nullptr; mWidget = nullptr; mMetroApp = nullptr; mWindow = nullptr; }
// Called after CoreApplication::Run(app) HRESULT MetroApp::CreateView(ABI::Windows::ApplicationModel::Core::IFrameworkView **aViewProvider) { // This entry point is called on the metro main thread, but the thread won't // be recognized as such until after Run() is called below. XPCOM has not // gone through startup at this point. // Note that we create the view which creates our native window for us. The // goanna widget gets created by goanna, and the two get hooked up later in // MetroWidget::Create(). LogFunction(); sFrameworkView = Make<FrameworkView>(this); sFrameworkView.Get()->AddRef(); *aViewProvider = sFrameworkView.Get(); return !sFrameworkView ? E_FAIL : S_OK; }
HRESULT FrameworkView::OnSettingsCommandInvoked(IUICommand* aCommand) { LogFunction(); HRESULT hr; uint32_t id; ComPtr<IPropertyValue> prop; AssertRetHRESULT(hr = aCommand->get_Id((IInspectable**)prop.GetAddressOf()), hr); AssertRetHRESULT(hr = prop->GetUInt32(&id), hr); nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService(); if (obs) { NS_ConvertASCIItoUTF16 idStr(nsPrintfCString("%lu", id)); obs->NotifyObservers(nullptr, "metro-settings-entry-selected", idStr.BeginReading()); } return S_OK; }
HRESULT FrameworkView::OnWindowSizeChanged(ICoreWindow* aSender, IWindowSizeChangedEventArgs* aArgs) { LogFunction(); if (mShuttingDown) { return S_OK; } NS_ASSERTION(mWindow, "SetWindow must be called before OnWindowSizeChanged!"); Rect logicalBounds; mWindow->get_Bounds(&logicalBounds); mWindowBounds = MetroUtils::LogToPhys(logicalBounds); UpdateWidgetSizeAndPosition(); FireViewStateObservers(); return S_OK; }
void FrameworkView::PerformURILoadOrSearch(HString& aString) { LogFunction(); if (WindowsIsStringEmpty(aString.Get())) { WinUtils::Log("Emptry string passed to PerformURILoadOrSearch"); return; } // If we have a URI then devert to load the URI directly ComPtr<IUriRuntimeClass> uri; MetroUtils::CreateUri(aString.Get(), uri); if (uri) { PerformURILoad(aString); } else { PerformSearch(aString); } }
HRESULT FrameworkView::ActivateView() { LogFunction(); UpdateWidgetSizeAndPosition(); nsIntRegion region(nsIntRect(0, 0, mWindowBounds.width, mWindowBounds.height)); mWidget->Paint(region); // Activate the window, this kills the splash screen mWindow->Activate(); ProcessLaunchArguments(); AddEventHandlers(); SetupContracts(); return S_OK; }
void FrameworkView::SetDpi(float aDpi) { if (aDpi != mDPI) { LogFunction(); mDPI = aDpi; // Often a DPI change implies a window size change. NS_ASSERTION(mWindow, "SetWindow must be called before SetDpi!"); Rect logicalBounds; mWindow->get_Bounds(&logicalBounds); // convert to physical (device) pixels mWindowBounds = MetroUtils::LogToPhys(logicalBounds); // notify the widget that dpi has changed if (mWidget) { mWidget->ChangedDPI(); } } }
// Called by MetroApp void FrameworkView::ShutdownXPCOM() { LogFunction(); mShuttingDown = true; if (mAutomationProvider) { ComPtr<IUIABridge> provider; mAutomationProvider.As(&provider); if (provider) { provider->Disconnect(); } } mAutomationProvider = nullptr; mMetroInput = nullptr; delete sSettingsArray; sSettingsArray = nullptr; mWidget = nullptr; mMetroApp = nullptr; mWindow = nullptr; }