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