forked from mirrors/gecko-dev
Backed out changeset edd529f7a9c5 (bug 1631568) Backed out changeset 1cc0881e244b (bug 1631568) Backed out changeset ed3c1e85d5e3 (bug1556556) Backed out changeset 38ffc6215bbf (bug1556556) Backed out changeset 03c2c25d8023 (bug1556556) Backed out changeset 9c717eb067b8 (bug1556556) Backed out changeset 98e26bc98b85 (bug1556556) Backed out changeset 05a6a581e755 (bug1556556) Backed out changeset 867946cf05bb (bug1556556) Backed out changeset 20d72a334530 (bug1556556) Backed out changeset 2c62e61d9054 (bug1556556) Backed out changeset 62a223d057d2 (bug1556556) Backed out changeset 2c5d55a1f0b1 (bug1556556) Backed out changeset 700447945b4e (bug1556556) Backed out changeset 93190ae4f5ff (bug1556556) Backed out changeset a7bd34d961bb (bug1556556) Backed out changeset fccd1d3c7189 (bug1556556) Backed out changeset 24056e47183d (bug1556556) Backed out changeset 204881474cc1 (bug1556556) Backed out changeset 387320881876 (bug1556556) Backed out changeset be8f5eb58460 (bug1556556) Backed out changeset 629c58a9166b (bug1556556) Backed out changeset 4312b2b5dda8 (bug1556556) Backed out changeset d11dbf6403a5 (bug1556556) Backed out changeset 95c54c023779 (bug1556556) Backed out changeset 80fcb7e71188 (bug1556556) Backed out changeset d75a4ecb0d47 (bug1556556) Backed out changeset 903c4de34e7a (bug1556556) Backed out changeset f15334a3e803 (bug1556556) Backed out changeset 9553e99137ea (bug1556556)
163 lines
5.6 KiB
C++
163 lines
5.6 KiB
C++
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
/* 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/. */
|
|
|
|
#include "nsImageFrame.h"
|
|
|
|
#include "mozilla/MouseEvents.h"
|
|
#include "mozilla/PresShell.h"
|
|
#include "nsIFormControlFrame.h"
|
|
#include "nsPresContext.h"
|
|
#include "nsGkAtoms.h"
|
|
#include "nsStyleConsts.h"
|
|
#include "nsCheckboxRadioFrame.h"
|
|
#include "nsLayoutUtils.h"
|
|
#include "nsIContent.h"
|
|
|
|
using namespace mozilla;
|
|
|
|
class nsImageControlFrame final : public nsImageFrame,
|
|
public nsIFormControlFrame {
|
|
public:
|
|
explicit nsImageControlFrame(ComputedStyle* aStyle,
|
|
nsPresContext* aPresContext);
|
|
~nsImageControlFrame() final;
|
|
|
|
void DestroyFrom(nsIFrame* aDestructRoot, PostDestroyData&) final;
|
|
void Init(nsIContent* aContent, nsContainerFrame* aParent,
|
|
nsIFrame* aPrevInFlow) final;
|
|
|
|
NS_DECL_QUERYFRAME
|
|
NS_DECL_FRAMEARENA_HELPERS(nsImageControlFrame)
|
|
|
|
void Reflow(nsPresContext*, ReflowOutput&, const ReflowInput&,
|
|
nsReflowStatus&) final;
|
|
|
|
nsresult HandleEvent(nsPresContext*, WidgetGUIEvent*, nsEventStatus*) final;
|
|
|
|
#ifdef ACCESSIBILITY
|
|
mozilla::a11y::AccType AccessibleType() final;
|
|
#endif
|
|
|
|
#ifdef DEBUG_FRAME_DUMP
|
|
nsresult GetFrameName(nsAString& aResult) const final {
|
|
return MakeFrameName(NS_LITERAL_STRING("ImageControl"), aResult);
|
|
}
|
|
#endif
|
|
|
|
Maybe<Cursor> GetCursor(const nsPoint&) final;
|
|
|
|
// nsIFormContromFrame
|
|
void SetFocus(bool aOn, bool aRepaint) final;
|
|
nsresult SetFormProperty(nsAtom* aName, const nsAString& aValue) final;
|
|
};
|
|
|
|
nsImageControlFrame::nsImageControlFrame(ComputedStyle* aStyle,
|
|
nsPresContext* aPresContext)
|
|
: nsImageFrame(aStyle, aPresContext, kClassID) {}
|
|
|
|
nsImageControlFrame::~nsImageControlFrame() = default;
|
|
|
|
void nsImageControlFrame::DestroyFrom(nsIFrame* aDestructRoot,
|
|
PostDestroyData& aPostDestroyData) {
|
|
if (!GetPrevInFlow()) {
|
|
nsCheckboxRadioFrame::RegUnRegAccessKey(this, false);
|
|
}
|
|
nsImageFrame::DestroyFrom(aDestructRoot, aPostDestroyData);
|
|
}
|
|
|
|
nsIFrame* NS_NewImageControlFrame(PresShell* aPresShell,
|
|
ComputedStyle* aStyle) {
|
|
return new (aPresShell)
|
|
nsImageControlFrame(aStyle, aPresShell->GetPresContext());
|
|
}
|
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsImageControlFrame)
|
|
|
|
void nsImageControlFrame::Init(nsIContent* aContent, nsContainerFrame* aParent,
|
|
nsIFrame* aPrevInFlow) {
|
|
nsImageFrame::Init(aContent, aParent, aPrevInFlow);
|
|
|
|
if (aPrevInFlow) {
|
|
return;
|
|
}
|
|
|
|
mContent->SetProperty(nsGkAtoms::imageClickedPoint, new nsIntPoint(0, 0),
|
|
nsINode::DeleteProperty<nsIntPoint>);
|
|
}
|
|
|
|
NS_QUERYFRAME_HEAD(nsImageControlFrame)
|
|
NS_QUERYFRAME_ENTRY(nsIFormControlFrame)
|
|
NS_QUERYFRAME_TAIL_INHERITING(nsImageFrame)
|
|
|
|
#ifdef ACCESSIBILITY
|
|
a11y::AccType nsImageControlFrame::AccessibleType() {
|
|
if (mContent->IsAnyOfHTMLElements(nsGkAtoms::button, nsGkAtoms::input)) {
|
|
return a11y::eHTMLButtonType;
|
|
}
|
|
|
|
return a11y::eNoType;
|
|
}
|
|
#endif
|
|
|
|
void nsImageControlFrame::Reflow(nsPresContext* aPresContext,
|
|
ReflowOutput& aDesiredSize,
|
|
const ReflowInput& aReflowInput,
|
|
nsReflowStatus& aStatus) {
|
|
DO_GLOBAL_REFLOW_COUNT("nsImageControlFrame");
|
|
DISPLAY_REFLOW(aPresContext, this, aReflowInput, aDesiredSize, aStatus);
|
|
MOZ_ASSERT(aStatus.IsEmpty(), "Caller should pass a fresh reflow status!");
|
|
if (!GetPrevInFlow() && (mState & NS_FRAME_FIRST_REFLOW)) {
|
|
nsCheckboxRadioFrame::RegUnRegAccessKey(this, true);
|
|
}
|
|
return nsImageFrame::Reflow(aPresContext, aDesiredSize, aReflowInput,
|
|
aStatus);
|
|
}
|
|
|
|
nsresult nsImageControlFrame::HandleEvent(nsPresContext* aPresContext,
|
|
WidgetGUIEvent* aEvent,
|
|
nsEventStatus* aEventStatus) {
|
|
NS_ENSURE_ARG_POINTER(aEventStatus);
|
|
|
|
// Don't do anything if the event has already been handled by someone
|
|
if (nsEventStatus_eConsumeNoDefault == *aEventStatus) {
|
|
return NS_OK;
|
|
}
|
|
|
|
if (IsContentDisabled()) {
|
|
return nsFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
|
|
}
|
|
|
|
*aEventStatus = nsEventStatus_eIgnore;
|
|
|
|
if (aEvent->mMessage == eMouseUp &&
|
|
aEvent->AsMouseEvent()->mButton == MouseButton::eLeft) {
|
|
// Store click point for HTMLInputElement::SubmitNamesValues
|
|
// Do this on MouseUp because the specs don't say and that's what IE does
|
|
nsIntPoint* lastClickPoint = static_cast<nsIntPoint*>(
|
|
mContent->GetProperty(nsGkAtoms::imageClickedPoint));
|
|
if (lastClickPoint) {
|
|
// normally lastClickedPoint is not null, as it's allocated in Init()
|
|
nsPoint pt = nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent, this);
|
|
TranslateEventCoords(pt, *lastClickPoint);
|
|
}
|
|
}
|
|
return nsImageFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
|
|
}
|
|
|
|
void nsImageControlFrame::SetFocus(bool aOn, bool aRepaint) {}
|
|
|
|
Maybe<nsIFrame::Cursor> nsImageControlFrame::GetCursor(const nsPoint&) {
|
|
StyleCursorKind kind = StyleUI()->mCursor.keyword;
|
|
if (kind == StyleCursorKind::Auto) {
|
|
kind = StyleCursorKind::Pointer;
|
|
}
|
|
return Some(Cursor{kind, AllowCustomCursorImage::Yes});
|
|
}
|
|
|
|
nsresult nsImageControlFrame::SetFormProperty(nsAtom* aName,
|
|
const nsAString& aValue) {
|
|
return NS_OK;
|
|
}
|