1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/accessible/src/windows/msaa/DocAccessibleWrap.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,157 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim: set ts=2 et sw=2 tw=80: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#include "DocAccessibleWrap.h" 1.11 + 1.12 +#include "Compatibility.h" 1.13 +#include "nsWinUtils.h" 1.14 +#include "mozilla/dom/TabChild.h" 1.15 +#include "Role.h" 1.16 +#include "RootAccessible.h" 1.17 +#include "sdnDocAccessible.h" 1.18 +#include "Statistics.h" 1.19 + 1.20 +#include "nsIDocShell.h" 1.21 +#include "nsIInterfaceRequestorUtils.h" 1.22 + 1.23 +using namespace mozilla; 1.24 +using namespace mozilla::a11y; 1.25 + 1.26 +//////////////////////////////////////////////////////////////////////////////// 1.27 +// DocAccessibleWrap 1.28 +//////////////////////////////////////////////////////////////////////////////// 1.29 + 1.30 +DocAccessibleWrap:: 1.31 + DocAccessibleWrap(nsIDocument* aDocument, nsIContent* aRootContent, 1.32 + nsIPresShell* aPresShell) : 1.33 + DocAccessible(aDocument, aRootContent, aPresShell), mHWND(nullptr) 1.34 +{ 1.35 +} 1.36 + 1.37 +DocAccessibleWrap::~DocAccessibleWrap() 1.38 +{ 1.39 +} 1.40 + 1.41 +IMPL_IUNKNOWN_QUERY_HEAD(DocAccessibleWrap) 1.42 + if (aIID == IID_ISimpleDOMDocument) { 1.43 + statistics::ISimpleDOMUsed(); 1.44 + *aInstancePtr = static_cast<ISimpleDOMDocument*>(new sdnDocAccessible(this)); 1.45 + static_cast<IUnknown*>(*aInstancePtr)->AddRef(); 1.46 + return S_OK; 1.47 + } 1.48 +IMPL_IUNKNOWN_QUERY_TAIL_INHERITED(HyperTextAccessibleWrap) 1.49 + 1.50 +STDMETHODIMP 1.51 +DocAccessibleWrap::get_accValue(VARIANT aVarChild, BSTR __RPC_FAR* aValue) 1.52 +{ 1.53 + A11Y_TRYBLOCK_BEGIN 1.54 + 1.55 + if (!aValue) 1.56 + return E_INVALIDARG; 1.57 + *aValue = nullptr; 1.58 + 1.59 + // For backwards-compat, we still support old MSAA hack to provide URL in accValue 1.60 + // Check for real value first 1.61 + HRESULT hr = AccessibleWrap::get_accValue(aVarChild, aValue); 1.62 + if (FAILED(hr) || *aValue || aVarChild.lVal != CHILDID_SELF) 1.63 + return hr; 1.64 + 1.65 + // If document is being used to create a widget, don't use the URL hack 1.66 + roles::Role role = Role(); 1.67 + if (role != roles::DOCUMENT && role != roles::APPLICATION && 1.68 + role != roles::DIALOG && role != roles::ALERT) 1.69 + return hr; 1.70 + 1.71 + nsAutoString URL; 1.72 + nsresult rv = GetURL(URL); 1.73 + if (URL.IsEmpty()) 1.74 + return S_FALSE; 1.75 + 1.76 + *aValue = ::SysAllocStringLen(URL.get(), URL.Length()); 1.77 + return *aValue ? S_OK : E_OUTOFMEMORY; 1.78 + 1.79 + A11Y_TRYBLOCK_END 1.80 +} 1.81 + 1.82 +//////////////////////////////////////////////////////////////////////////////// 1.83 +// Accessible 1.84 + 1.85 +void 1.86 +DocAccessibleWrap::Shutdown() 1.87 +{ 1.88 + // Do window emulation specific shutdown if emulation was started. 1.89 + if (nsWinUtils::IsWindowEmulationStarted()) { 1.90 + // Destroy window created for root document. 1.91 + if (mDocFlags & eTabDocument) { 1.92 + nsWinUtils::sHWNDCache->Remove(mHWND); 1.93 + ::DestroyWindow(static_cast<HWND>(mHWND)); 1.94 + } 1.95 + 1.96 + mHWND = nullptr; 1.97 + } 1.98 + 1.99 + DocAccessible::Shutdown(); 1.100 +} 1.101 + 1.102 +//////////////////////////////////////////////////////////////////////////////// 1.103 +// DocAccessible public 1.104 + 1.105 +void* 1.106 +DocAccessibleWrap::GetNativeWindow() const 1.107 +{ 1.108 + return mHWND ? mHWND : DocAccessible::GetNativeWindow(); 1.109 +} 1.110 + 1.111 +//////////////////////////////////////////////////////////////////////////////// 1.112 +// DocAccessible protected 1.113 + 1.114 +void 1.115 +DocAccessibleWrap::DoInitialUpdate() 1.116 +{ 1.117 + DocAccessible::DoInitialUpdate(); 1.118 + 1.119 + if (nsWinUtils::IsWindowEmulationStarted()) { 1.120 + // Create window for tab document. 1.121 + if (mDocFlags & eTabDocument) { 1.122 + mozilla::dom::TabChild* tabChild = 1.123 + mozilla::dom::TabChild::GetFrom(mDocumentNode->GetShell()); 1.124 + 1.125 + a11y::RootAccessible* rootDocument = RootAccessible(); 1.126 + 1.127 + mozilla::WindowsHandle nativeData = 0; 1.128 + if (tabChild) 1.129 + tabChild->SendGetWidgetNativeData(&nativeData); 1.130 + else 1.131 + nativeData = reinterpret_cast<mozilla::WindowsHandle>( 1.132 + rootDocument->GetNativeWindow()); 1.133 + 1.134 + bool isActive = true; 1.135 + int32_t x = CW_USEDEFAULT, y = CW_USEDEFAULT, width = 0, height = 0; 1.136 + if (Compatibility::IsDolphin()) { 1.137 + GetBounds(&x, &y, &width, &height); 1.138 + int32_t rootX = 0, rootY = 0, rootWidth = 0, rootHeight = 0; 1.139 + rootDocument->GetBounds(&rootX, &rootY, &rootWidth, &rootHeight); 1.140 + x = rootX - x; 1.141 + y -= rootY; 1.142 + 1.143 + nsCOMPtr<nsISupports> container = mDocumentNode->GetContainer(); 1.144 + nsCOMPtr<nsIDocShell> docShell = do_QueryInterface(container); 1.145 + docShell->GetIsActive(&isActive); 1.146 + } 1.147 + 1.148 + HWND parentWnd = reinterpret_cast<HWND>(nativeData); 1.149 + mHWND = nsWinUtils::CreateNativeWindow(kClassNameTabContent, parentWnd, 1.150 + x, y, width, height, isActive); 1.151 + 1.152 + nsWinUtils::sHWNDCache->Put(mHWND, this); 1.153 + 1.154 + } else { 1.155 + DocAccessible* parentDocument = ParentDocument(); 1.156 + if (parentDocument) 1.157 + mHWND = parentDocument->GetNativeWindow(); 1.158 + } 1.159 + } 1.160 +}