Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* vim: set ts=2 et sw=2 tw=80: */ |
michael@0 | 3 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | #include "DocAccessibleWrap.h" |
michael@0 | 8 | |
michael@0 | 9 | #include "Compatibility.h" |
michael@0 | 10 | #include "nsWinUtils.h" |
michael@0 | 11 | #include "mozilla/dom/TabChild.h" |
michael@0 | 12 | #include "Role.h" |
michael@0 | 13 | #include "RootAccessible.h" |
michael@0 | 14 | #include "sdnDocAccessible.h" |
michael@0 | 15 | #include "Statistics.h" |
michael@0 | 16 | |
michael@0 | 17 | #include "nsIDocShell.h" |
michael@0 | 18 | #include "nsIInterfaceRequestorUtils.h" |
michael@0 | 19 | |
michael@0 | 20 | using namespace mozilla; |
michael@0 | 21 | using namespace mozilla::a11y; |
michael@0 | 22 | |
michael@0 | 23 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 24 | // DocAccessibleWrap |
michael@0 | 25 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 26 | |
michael@0 | 27 | DocAccessibleWrap:: |
michael@0 | 28 | DocAccessibleWrap(nsIDocument* aDocument, nsIContent* aRootContent, |
michael@0 | 29 | nsIPresShell* aPresShell) : |
michael@0 | 30 | DocAccessible(aDocument, aRootContent, aPresShell), mHWND(nullptr) |
michael@0 | 31 | { |
michael@0 | 32 | } |
michael@0 | 33 | |
michael@0 | 34 | DocAccessibleWrap::~DocAccessibleWrap() |
michael@0 | 35 | { |
michael@0 | 36 | } |
michael@0 | 37 | |
michael@0 | 38 | IMPL_IUNKNOWN_QUERY_HEAD(DocAccessibleWrap) |
michael@0 | 39 | if (aIID == IID_ISimpleDOMDocument) { |
michael@0 | 40 | statistics::ISimpleDOMUsed(); |
michael@0 | 41 | *aInstancePtr = static_cast<ISimpleDOMDocument*>(new sdnDocAccessible(this)); |
michael@0 | 42 | static_cast<IUnknown*>(*aInstancePtr)->AddRef(); |
michael@0 | 43 | return S_OK; |
michael@0 | 44 | } |
michael@0 | 45 | IMPL_IUNKNOWN_QUERY_TAIL_INHERITED(HyperTextAccessibleWrap) |
michael@0 | 46 | |
michael@0 | 47 | STDMETHODIMP |
michael@0 | 48 | DocAccessibleWrap::get_accValue(VARIANT aVarChild, BSTR __RPC_FAR* aValue) |
michael@0 | 49 | { |
michael@0 | 50 | A11Y_TRYBLOCK_BEGIN |
michael@0 | 51 | |
michael@0 | 52 | if (!aValue) |
michael@0 | 53 | return E_INVALIDARG; |
michael@0 | 54 | *aValue = nullptr; |
michael@0 | 55 | |
michael@0 | 56 | // For backwards-compat, we still support old MSAA hack to provide URL in accValue |
michael@0 | 57 | // Check for real value first |
michael@0 | 58 | HRESULT hr = AccessibleWrap::get_accValue(aVarChild, aValue); |
michael@0 | 59 | if (FAILED(hr) || *aValue || aVarChild.lVal != CHILDID_SELF) |
michael@0 | 60 | return hr; |
michael@0 | 61 | |
michael@0 | 62 | // If document is being used to create a widget, don't use the URL hack |
michael@0 | 63 | roles::Role role = Role(); |
michael@0 | 64 | if (role != roles::DOCUMENT && role != roles::APPLICATION && |
michael@0 | 65 | role != roles::DIALOG && role != roles::ALERT) |
michael@0 | 66 | return hr; |
michael@0 | 67 | |
michael@0 | 68 | nsAutoString URL; |
michael@0 | 69 | nsresult rv = GetURL(URL); |
michael@0 | 70 | if (URL.IsEmpty()) |
michael@0 | 71 | return S_FALSE; |
michael@0 | 72 | |
michael@0 | 73 | *aValue = ::SysAllocStringLen(URL.get(), URL.Length()); |
michael@0 | 74 | return *aValue ? S_OK : E_OUTOFMEMORY; |
michael@0 | 75 | |
michael@0 | 76 | A11Y_TRYBLOCK_END |
michael@0 | 77 | } |
michael@0 | 78 | |
michael@0 | 79 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 80 | // Accessible |
michael@0 | 81 | |
michael@0 | 82 | void |
michael@0 | 83 | DocAccessibleWrap::Shutdown() |
michael@0 | 84 | { |
michael@0 | 85 | // Do window emulation specific shutdown if emulation was started. |
michael@0 | 86 | if (nsWinUtils::IsWindowEmulationStarted()) { |
michael@0 | 87 | // Destroy window created for root document. |
michael@0 | 88 | if (mDocFlags & eTabDocument) { |
michael@0 | 89 | nsWinUtils::sHWNDCache->Remove(mHWND); |
michael@0 | 90 | ::DestroyWindow(static_cast<HWND>(mHWND)); |
michael@0 | 91 | } |
michael@0 | 92 | |
michael@0 | 93 | mHWND = nullptr; |
michael@0 | 94 | } |
michael@0 | 95 | |
michael@0 | 96 | DocAccessible::Shutdown(); |
michael@0 | 97 | } |
michael@0 | 98 | |
michael@0 | 99 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 100 | // DocAccessible public |
michael@0 | 101 | |
michael@0 | 102 | void* |
michael@0 | 103 | DocAccessibleWrap::GetNativeWindow() const |
michael@0 | 104 | { |
michael@0 | 105 | return mHWND ? mHWND : DocAccessible::GetNativeWindow(); |
michael@0 | 106 | } |
michael@0 | 107 | |
michael@0 | 108 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 109 | // DocAccessible protected |
michael@0 | 110 | |
michael@0 | 111 | void |
michael@0 | 112 | DocAccessibleWrap::DoInitialUpdate() |
michael@0 | 113 | { |
michael@0 | 114 | DocAccessible::DoInitialUpdate(); |
michael@0 | 115 | |
michael@0 | 116 | if (nsWinUtils::IsWindowEmulationStarted()) { |
michael@0 | 117 | // Create window for tab document. |
michael@0 | 118 | if (mDocFlags & eTabDocument) { |
michael@0 | 119 | mozilla::dom::TabChild* tabChild = |
michael@0 | 120 | mozilla::dom::TabChild::GetFrom(mDocumentNode->GetShell()); |
michael@0 | 121 | |
michael@0 | 122 | a11y::RootAccessible* rootDocument = RootAccessible(); |
michael@0 | 123 | |
michael@0 | 124 | mozilla::WindowsHandle nativeData = 0; |
michael@0 | 125 | if (tabChild) |
michael@0 | 126 | tabChild->SendGetWidgetNativeData(&nativeData); |
michael@0 | 127 | else |
michael@0 | 128 | nativeData = reinterpret_cast<mozilla::WindowsHandle>( |
michael@0 | 129 | rootDocument->GetNativeWindow()); |
michael@0 | 130 | |
michael@0 | 131 | bool isActive = true; |
michael@0 | 132 | int32_t x = CW_USEDEFAULT, y = CW_USEDEFAULT, width = 0, height = 0; |
michael@0 | 133 | if (Compatibility::IsDolphin()) { |
michael@0 | 134 | GetBounds(&x, &y, &width, &height); |
michael@0 | 135 | int32_t rootX = 0, rootY = 0, rootWidth = 0, rootHeight = 0; |
michael@0 | 136 | rootDocument->GetBounds(&rootX, &rootY, &rootWidth, &rootHeight); |
michael@0 | 137 | x = rootX - x; |
michael@0 | 138 | y -= rootY; |
michael@0 | 139 | |
michael@0 | 140 | nsCOMPtr<nsISupports> container = mDocumentNode->GetContainer(); |
michael@0 | 141 | nsCOMPtr<nsIDocShell> docShell = do_QueryInterface(container); |
michael@0 | 142 | docShell->GetIsActive(&isActive); |
michael@0 | 143 | } |
michael@0 | 144 | |
michael@0 | 145 | HWND parentWnd = reinterpret_cast<HWND>(nativeData); |
michael@0 | 146 | mHWND = nsWinUtils::CreateNativeWindow(kClassNameTabContent, parentWnd, |
michael@0 | 147 | x, y, width, height, isActive); |
michael@0 | 148 | |
michael@0 | 149 | nsWinUtils::sHWNDCache->Put(mHWND, this); |
michael@0 | 150 | |
michael@0 | 151 | } else { |
michael@0 | 152 | DocAccessible* parentDocument = ParentDocument(); |
michael@0 | 153 | if (parentDocument) |
michael@0 | 154 | mHWND = parentDocument->GetNativeWindow(); |
michael@0 | 155 | } |
michael@0 | 156 | } |
michael@0 | 157 | } |