2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsTitleBarFrame.h"
|
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIDOMNodeList.h"
|
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsIWidget.h"
|
2007-04-20 03:56:49 -07:00
|
|
|
#include "nsMenuPopupFrame.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsPresContext.h"
|
2013-11-20 11:18:25 -08:00
|
|
|
#include "nsIDocShell.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsPIDOMWindow.h"
|
|
|
|
#include "nsDisplayList.h"
|
2009-06-30 00:56:40 -07:00
|
|
|
#include "nsContentUtils.h"
|
2013-09-25 04:21:18 -07:00
|
|
|
#include "mozilla/MouseEvents.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-08-02 00:05:16 -07:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
//
|
|
|
|
// NS_NewTitleBarFrame
|
|
|
|
//
|
|
|
|
// Creates a new TitleBar frame and returns it
|
|
|
|
//
|
|
|
|
nsIFrame*
|
|
|
|
NS_NewTitleBarFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
|
|
|
{
|
2015-01-06 01:27:56 -08:00
|
|
|
return new (aPresShell) nsTitleBarFrame(aContext);
|
2009-09-12 09:49:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsTitleBarFrame)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2015-01-06 01:27:56 -08:00
|
|
|
nsTitleBarFrame::nsTitleBarFrame(nsStyleContext* aContext)
|
|
|
|
:nsBoxFrame(aContext, false)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
mTrackingMouseMove = false;
|
2010-11-30 06:59:46 -08:00
|
|
|
UpdateMouseThrough();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-02-14 03:12:27 -08:00
|
|
|
void
|
2007-03-22 10:30:00 -07:00
|
|
|
nsTitleBarFrame::BuildDisplayListForChildren(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsDisplayListSet& aLists)
|
|
|
|
{
|
|
|
|
// override, since we don't want children to get events
|
|
|
|
if (aBuilder->IsForEventDelivery()) {
|
2008-04-21 09:53:30 -07:00
|
|
|
if (!mContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::allowevents,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsGkAtoms::_true, eCaseMatters))
|
2013-02-14 03:12:27 -08:00
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2013-02-14 03:12:27 -08:00
|
|
|
nsBoxFrame::BuildDisplayListForChildren(aBuilder, aDirtyRect, aLists);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2014-02-17 23:47:48 -08:00
|
|
|
nsresult
|
2007-03-22 10:30:00 -07:00
|
|
|
nsTitleBarFrame::HandleEvent(nsPresContext* aPresContext,
|
2013-10-01 20:46:03 -07:00
|
|
|
WidgetGUIEvent* aEvent,
|
|
|
|
nsEventStatus* aEventStatus)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-02-27 02:48:25 -08:00
|
|
|
NS_ENSURE_ARG_POINTER(aEventStatus);
|
|
|
|
if (nsEventStatus_eConsumeNoDefault == *aEventStatus) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool doDefault = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
switch (aEvent->message) {
|
|
|
|
|
|
|
|
case NS_MOUSE_BUTTON_DOWN: {
|
2013-10-22 01:55:20 -07:00
|
|
|
if (aEvent->AsMouseEvent()->button == WidgetMouseEvent::eLeftButton) {
|
2007-04-20 03:56:49 -07:00
|
|
|
// titlebar has no effect in non-chrome shells
|
2013-11-20 11:18:25 -08:00
|
|
|
nsCOMPtr<nsIDocShellTreeItem> dsti = aPresContext->GetDocShell();
|
2007-04-20 03:56:49 -07:00
|
|
|
if (dsti) {
|
2014-01-19 23:58:26 -08:00
|
|
|
if (dsti->ItemType() == nsIDocShellTreeItem::typeChrome) {
|
2007-04-20 03:56:49 -07:00
|
|
|
// we're tracking.
|
2011-10-17 07:59:28 -07:00
|
|
|
mTrackingMouseMove = true;
|
2007-04-20 03:56:49 -07:00
|
|
|
|
|
|
|
// start capture.
|
2009-09-13 06:13:16 -07:00
|
|
|
nsIPresShell::SetCapturingContent(GetContent(), CAPTURE_IGNOREALLOWED);
|
2007-04-20 03:56:49 -07:00
|
|
|
|
|
|
|
// remember current mouse coordinates.
|
2013-08-02 00:05:16 -07:00
|
|
|
mLastPoint = LayoutDeviceIntPoint::ToUntyped(aEvent->refPoint);
|
2007-04-20 03:56:49 -07:00
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
*aEventStatus = nsEventStatus_eConsumeNoDefault;
|
2011-10-17 07:59:28 -07:00
|
|
|
doDefault = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case NS_MOUSE_BUTTON_UP: {
|
2013-10-22 01:55:20 -07:00
|
|
|
if (mTrackingMouseMove &&
|
|
|
|
aEvent->AsMouseEvent()->button == WidgetMouseEvent::eLeftButton) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// we're done tracking.
|
2011-10-17 07:59:28 -07:00
|
|
|
mTrackingMouseMove = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// end capture
|
2012-07-30 07:20:58 -07:00
|
|
|
nsIPresShell::SetCapturingContent(nullptr, 0);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
*aEventStatus = nsEventStatus_eConsumeNoDefault;
|
2011-10-17 07:59:28 -07:00
|
|
|
doDefault = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_MOUSE_MOVE: {
|
|
|
|
if(mTrackingMouseMove)
|
|
|
|
{
|
2013-08-02 00:05:16 -07:00
|
|
|
nsIntPoint nsMoveBy = LayoutDeviceIntPoint::ToUntyped(aEvent->refPoint) - mLastPoint;
|
2007-04-20 03:56:49 -07:00
|
|
|
|
|
|
|
nsIFrame* parent = GetParent();
|
2012-07-30 17:43:28 -07:00
|
|
|
while (parent) {
|
|
|
|
nsMenuPopupFrame* popupFrame = do_QueryFrame(parent);
|
|
|
|
if (popupFrame)
|
|
|
|
break;
|
2007-04-20 03:56:49 -07:00
|
|
|
parent = parent->GetParent();
|
2012-07-30 17:43:28 -07:00
|
|
|
}
|
2007-04-20 03:56:49 -07:00
|
|
|
|
2010-02-01 07:11:08 -08:00
|
|
|
// if the titlebar is in a popup, move the popup frame, otherwise
|
2007-04-20 03:56:49 -07:00
|
|
|
// move the widget associated with the window
|
|
|
|
if (parent) {
|
2010-02-01 07:11:08 -08:00
|
|
|
nsMenuPopupFrame* menuPopupFrame = static_cast<nsMenuPopupFrame*>(parent);
|
2011-12-01 13:35:42 -08:00
|
|
|
nsCOMPtr<nsIWidget> widget = menuPopupFrame->GetWidget();
|
2009-01-14 19:27:09 -08:00
|
|
|
nsIntRect bounds;
|
2007-04-20 03:56:49 -07:00
|
|
|
widget->GetScreenBounds(bounds);
|
2014-04-08 05:45:52 -07:00
|
|
|
|
|
|
|
int32_t newx = aPresContext->DevPixelsToIntCSSPixels(bounds.x + nsMoveBy.x);
|
|
|
|
int32_t newy = aPresContext->DevPixelsToIntCSSPixels(bounds.y + nsMoveBy.y);
|
|
|
|
menuPopupFrame->MoveTo(newx, newy, false);
|
2007-04-20 03:56:49 -07:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
nsIPresShell* presShell = aPresContext->PresShell();
|
|
|
|
nsPIDOMWindow *window = presShell->GetDocument()->GetWindow();
|
2008-09-28 12:14:28 -07:00
|
|
|
if (window) {
|
|
|
|
window->MoveBy(nsMoveBy.x, nsMoveBy.y);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
*aEventStatus = nsEventStatus_eConsumeNoDefault;
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
doDefault = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2013-10-28 02:03:19 -07:00
|
|
|
case NS_MOUSE_CLICK: {
|
|
|
|
WidgetMouseEvent* mouseEvent = aEvent->AsMouseEvent();
|
|
|
|
if (mouseEvent->IsLeftClickEvent()) {
|
|
|
|
MouseClicked(aPresContext, mouseEvent);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
break;
|
2013-10-28 02:03:19 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( doDefault )
|
|
|
|
return nsBoxFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
|
|
|
|
else
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-10-01 20:46:03 -07:00
|
|
|
nsTitleBarFrame::MouseClicked(nsPresContext* aPresContext,
|
2013-10-28 02:03:19 -07:00
|
|
|
WidgetMouseEvent* aEvent)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// Execute the oncommand event handler.
|
2009-06-30 00:56:40 -07:00
|
|
|
nsContentUtils::DispatchXULCommand(mContent,
|
2012-12-15 17:26:03 -08:00
|
|
|
aEvent && aEvent->mFlags.mIsTrusted);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|