Thu, 15 Jan 2015 15:59:08 +0100
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: 2; 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 "nsCOMPtr.h" |
michael@0 | 7 | #include "nsTitleBarFrame.h" |
michael@0 | 8 | #include "nsIContent.h" |
michael@0 | 9 | #include "nsIDocument.h" |
michael@0 | 10 | #include "nsIDOMNodeList.h" |
michael@0 | 11 | #include "nsGkAtoms.h" |
michael@0 | 12 | #include "nsIWidget.h" |
michael@0 | 13 | #include "nsMenuPopupFrame.h" |
michael@0 | 14 | #include "nsPresContext.h" |
michael@0 | 15 | #include "nsIDocShell.h" |
michael@0 | 16 | #include "nsPIDOMWindow.h" |
michael@0 | 17 | #include "nsDisplayList.h" |
michael@0 | 18 | #include "nsContentUtils.h" |
michael@0 | 19 | #include "mozilla/MouseEvents.h" |
michael@0 | 20 | |
michael@0 | 21 | using namespace mozilla; |
michael@0 | 22 | |
michael@0 | 23 | // |
michael@0 | 24 | // NS_NewTitleBarFrame |
michael@0 | 25 | // |
michael@0 | 26 | // Creates a new TitleBar frame and returns it |
michael@0 | 27 | // |
michael@0 | 28 | nsIFrame* |
michael@0 | 29 | NS_NewTitleBarFrame(nsIPresShell* aPresShell, nsStyleContext* aContext) |
michael@0 | 30 | { |
michael@0 | 31 | return new (aPresShell) nsTitleBarFrame(aPresShell, aContext); |
michael@0 | 32 | } |
michael@0 | 33 | |
michael@0 | 34 | NS_IMPL_FRAMEARENA_HELPERS(nsTitleBarFrame) |
michael@0 | 35 | |
michael@0 | 36 | nsTitleBarFrame::nsTitleBarFrame(nsIPresShell* aPresShell, nsStyleContext* aContext) |
michael@0 | 37 | :nsBoxFrame(aPresShell, aContext, false) |
michael@0 | 38 | { |
michael@0 | 39 | mTrackingMouseMove = false; |
michael@0 | 40 | UpdateMouseThrough(); |
michael@0 | 41 | } |
michael@0 | 42 | |
michael@0 | 43 | void |
michael@0 | 44 | nsTitleBarFrame::BuildDisplayListForChildren(nsDisplayListBuilder* aBuilder, |
michael@0 | 45 | const nsRect& aDirtyRect, |
michael@0 | 46 | const nsDisplayListSet& aLists) |
michael@0 | 47 | { |
michael@0 | 48 | // override, since we don't want children to get events |
michael@0 | 49 | if (aBuilder->IsForEventDelivery()) { |
michael@0 | 50 | if (!mContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::allowevents, |
michael@0 | 51 | nsGkAtoms::_true, eCaseMatters)) |
michael@0 | 52 | return; |
michael@0 | 53 | } |
michael@0 | 54 | nsBoxFrame::BuildDisplayListForChildren(aBuilder, aDirtyRect, aLists); |
michael@0 | 55 | } |
michael@0 | 56 | |
michael@0 | 57 | nsresult |
michael@0 | 58 | nsTitleBarFrame::HandleEvent(nsPresContext* aPresContext, |
michael@0 | 59 | WidgetGUIEvent* aEvent, |
michael@0 | 60 | nsEventStatus* aEventStatus) |
michael@0 | 61 | { |
michael@0 | 62 | NS_ENSURE_ARG_POINTER(aEventStatus); |
michael@0 | 63 | if (nsEventStatus_eConsumeNoDefault == *aEventStatus) { |
michael@0 | 64 | return NS_OK; |
michael@0 | 65 | } |
michael@0 | 66 | |
michael@0 | 67 | bool doDefault = true; |
michael@0 | 68 | |
michael@0 | 69 | switch (aEvent->message) { |
michael@0 | 70 | |
michael@0 | 71 | case NS_MOUSE_BUTTON_DOWN: { |
michael@0 | 72 | if (aEvent->AsMouseEvent()->button == WidgetMouseEvent::eLeftButton) { |
michael@0 | 73 | // titlebar has no effect in non-chrome shells |
michael@0 | 74 | nsCOMPtr<nsIDocShellTreeItem> dsti = aPresContext->GetDocShell(); |
michael@0 | 75 | if (dsti) { |
michael@0 | 76 | if (dsti->ItemType() == nsIDocShellTreeItem::typeChrome) { |
michael@0 | 77 | // we're tracking. |
michael@0 | 78 | mTrackingMouseMove = true; |
michael@0 | 79 | |
michael@0 | 80 | // start capture. |
michael@0 | 81 | nsIPresShell::SetCapturingContent(GetContent(), CAPTURE_IGNOREALLOWED); |
michael@0 | 82 | |
michael@0 | 83 | // remember current mouse coordinates. |
michael@0 | 84 | mLastPoint = LayoutDeviceIntPoint::ToUntyped(aEvent->refPoint); |
michael@0 | 85 | } |
michael@0 | 86 | } |
michael@0 | 87 | |
michael@0 | 88 | *aEventStatus = nsEventStatus_eConsumeNoDefault; |
michael@0 | 89 | doDefault = false; |
michael@0 | 90 | } |
michael@0 | 91 | } |
michael@0 | 92 | break; |
michael@0 | 93 | |
michael@0 | 94 | |
michael@0 | 95 | case NS_MOUSE_BUTTON_UP: { |
michael@0 | 96 | if (mTrackingMouseMove && |
michael@0 | 97 | aEvent->AsMouseEvent()->button == WidgetMouseEvent::eLeftButton) { |
michael@0 | 98 | // we're done tracking. |
michael@0 | 99 | mTrackingMouseMove = false; |
michael@0 | 100 | |
michael@0 | 101 | // end capture |
michael@0 | 102 | nsIPresShell::SetCapturingContent(nullptr, 0); |
michael@0 | 103 | |
michael@0 | 104 | *aEventStatus = nsEventStatus_eConsumeNoDefault; |
michael@0 | 105 | doDefault = false; |
michael@0 | 106 | } |
michael@0 | 107 | } |
michael@0 | 108 | break; |
michael@0 | 109 | |
michael@0 | 110 | case NS_MOUSE_MOVE: { |
michael@0 | 111 | if(mTrackingMouseMove) |
michael@0 | 112 | { |
michael@0 | 113 | nsIntPoint nsMoveBy = LayoutDeviceIntPoint::ToUntyped(aEvent->refPoint) - mLastPoint; |
michael@0 | 114 | |
michael@0 | 115 | nsIFrame* parent = GetParent(); |
michael@0 | 116 | while (parent) { |
michael@0 | 117 | nsMenuPopupFrame* popupFrame = do_QueryFrame(parent); |
michael@0 | 118 | if (popupFrame) |
michael@0 | 119 | break; |
michael@0 | 120 | parent = parent->GetParent(); |
michael@0 | 121 | } |
michael@0 | 122 | |
michael@0 | 123 | // if the titlebar is in a popup, move the popup frame, otherwise |
michael@0 | 124 | // move the widget associated with the window |
michael@0 | 125 | if (parent) { |
michael@0 | 126 | nsMenuPopupFrame* menuPopupFrame = static_cast<nsMenuPopupFrame*>(parent); |
michael@0 | 127 | nsCOMPtr<nsIWidget> widget = menuPopupFrame->GetWidget(); |
michael@0 | 128 | nsIntRect bounds; |
michael@0 | 129 | widget->GetScreenBounds(bounds); |
michael@0 | 130 | |
michael@0 | 131 | int32_t newx = aPresContext->DevPixelsToIntCSSPixels(bounds.x + nsMoveBy.x); |
michael@0 | 132 | int32_t newy = aPresContext->DevPixelsToIntCSSPixels(bounds.y + nsMoveBy.y); |
michael@0 | 133 | menuPopupFrame->MoveTo(newx, newy, false); |
michael@0 | 134 | } |
michael@0 | 135 | else { |
michael@0 | 136 | nsIPresShell* presShell = aPresContext->PresShell(); |
michael@0 | 137 | nsPIDOMWindow *window = presShell->GetDocument()->GetWindow(); |
michael@0 | 138 | if (window) { |
michael@0 | 139 | window->MoveBy(nsMoveBy.x, nsMoveBy.y); |
michael@0 | 140 | } |
michael@0 | 141 | } |
michael@0 | 142 | |
michael@0 | 143 | *aEventStatus = nsEventStatus_eConsumeNoDefault; |
michael@0 | 144 | |
michael@0 | 145 | doDefault = false; |
michael@0 | 146 | } |
michael@0 | 147 | } |
michael@0 | 148 | break; |
michael@0 | 149 | |
michael@0 | 150 | case NS_MOUSE_CLICK: { |
michael@0 | 151 | WidgetMouseEvent* mouseEvent = aEvent->AsMouseEvent(); |
michael@0 | 152 | if (mouseEvent->IsLeftClickEvent()) { |
michael@0 | 153 | MouseClicked(aPresContext, mouseEvent); |
michael@0 | 154 | } |
michael@0 | 155 | break; |
michael@0 | 156 | } |
michael@0 | 157 | } |
michael@0 | 158 | |
michael@0 | 159 | if ( doDefault ) |
michael@0 | 160 | return nsBoxFrame::HandleEvent(aPresContext, aEvent, aEventStatus); |
michael@0 | 161 | else |
michael@0 | 162 | return NS_OK; |
michael@0 | 163 | } |
michael@0 | 164 | |
michael@0 | 165 | void |
michael@0 | 166 | nsTitleBarFrame::MouseClicked(nsPresContext* aPresContext, |
michael@0 | 167 | WidgetMouseEvent* aEvent) |
michael@0 | 168 | { |
michael@0 | 169 | // Execute the oncommand event handler. |
michael@0 | 170 | nsContentUtils::DispatchXULCommand(mContent, |
michael@0 | 171 | aEvent && aEvent->mFlags.mIsTrusted); |
michael@0 | 172 | } |