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