2020-02-10 19:26:01 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 40; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* 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 "nsNativeBasicTheme.h"
|
|
|
|
|
|
|
|
#include "mozilla/StaticPrefs_layout.h"
|
2020-03-03 19:46:41 +00:00
|
|
|
#include "mozilla/ClearOnShutdown.h"
|
2020-02-10 19:26:01 +00:00
|
|
|
#include "nsComboboxControlFrame.h"
|
|
|
|
#include "nsCSSRendering.h"
|
|
|
|
#include "nsDateTimeControlFrame.h"
|
|
|
|
#include "nsDeviceContext.h"
|
|
|
|
#include "PathHelpers.h"
|
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::gfx;
|
|
|
|
using namespace mozilla::widget;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace widget {
|
|
|
|
|
|
|
|
static const Color sBackgroundColor(Color(1.0f, 1.0f, 1.0f));
|
|
|
|
static const Color sBackgroundActiveColor(Color(0.88f, 0.88f, 0.9f));
|
|
|
|
static const Color sBackgroundActiveColorDisabled(Color(0.88f, 0.88f, 0.9f,
|
|
|
|
0.4f));
|
|
|
|
static const Color sBorderColor(Color(0.62f, 0.62f, 0.68f));
|
|
|
|
static const Color sBorderColorDisabled(Color(0.44f, 0.44f, 0.44f, 0.4f));
|
|
|
|
static const Color sBorderHoverColor(Color(0.5f, 0.5f, 0.56f));
|
|
|
|
static const Color sBorderHoverColorDisabled(Color(0.5f, 0.5f, 0.56f, 0.4f));
|
|
|
|
static const Color sBorderFocusColor(Color(0.04f, 0.52f, 1.0f));
|
|
|
|
static const Color sCheckBackgroundColor(Color(0.18f, 0.39f, 0.89f));
|
|
|
|
static const Color sCheckBackgroundColorDisabled(Color(0.18f, 0.39f, 0.89f,
|
|
|
|
0.4f));
|
|
|
|
static const Color sCheckBackgroundHoverColor(Color(0.02f, 0.24f, 0.58f));
|
|
|
|
static const Color sCheckBackgroundHoverColorDisabled(Color(0.02f, 0.24f, 0.58f,
|
|
|
|
0.4f));
|
|
|
|
static const Color sCheckBackgroundActiveColor(Color(0.03f, 0.19f, 0.45f));
|
|
|
|
static const Color sCheckBackgroundActiveColorDisabled(Color(0.03f, 0.19f,
|
|
|
|
0.45f, 0.4f));
|
|
|
|
static const Color sDisabledColor(Color(0.89f, 0.89f, 0.89f));
|
|
|
|
static const Color sActiveColor(Color(0.47f, 0.47f, 0.48f));
|
|
|
|
static const Color sInputHoverColor(Color(0.05f, 0.05f, 0.05f, 0.5f));
|
|
|
|
static const Color sRangeInputBackgroundColor(Color(0.89f, 0.89f, 0.89f));
|
|
|
|
static const Color sScrollbarColor(Color(0.94f, 0.94f, 0.94f));
|
|
|
|
static const Color sScrollbarBorderColor(Color(1.0f, 1.0f, 1.0f));
|
|
|
|
static const Color sScrollbarThumbColor(Color(0.8f, 0.8f, 0.8f));
|
|
|
|
static const Color sScrollbarThumbColorActive(Color(0.375f, 0.375f, 0.375f));
|
|
|
|
static const Color sScrollbarThumbColorHover(Color(0.65f, 0.65f, 0.65f));
|
|
|
|
static const Color sScrollbarArrowColor(Color(0.375f, 0.375f, 0.375f));
|
|
|
|
static const Color sScrollbarArrowColorActive(Color(1.0f, 1.0f, 1.0f));
|
|
|
|
static const Color sScrollbarArrowColorHover(Color(0.0f, 0.0f, 0.0f));
|
|
|
|
static const Color sScrollbarButtonColor(sScrollbarColor);
|
|
|
|
static const Color sScrollbarButtonActiveColor(Color(0.375f, 0.375f, 0.375f));
|
|
|
|
static const Color sScrollbarButtonHoverColor(Color(0.86f, 0.86f, 0.86f));
|
|
|
|
static const Color sButtonColor(Color(0.98f, 0.98f, 0.98f));
|
|
|
|
static const Color sButtonHoverColor(Color(0.94f, 0.94f, 0.96f));
|
|
|
|
static const Color sButtonActiveColor(Color(0.88f, 0.88f, 0.90f));
|
|
|
|
static const Color sWhiteColor(Color(1.0f, 1.0f, 1.0f, 0.0f));
|
|
|
|
|
2020-03-07 09:57:42 +00:00
|
|
|
static const CSSIntCoord kMinimumWidgetSize = 17;
|
|
|
|
|
2020-02-10 19:26:01 +00:00
|
|
|
} // namespace widget
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS_INHERITED(nsNativeBasicTheme, nsNativeTheme, nsITheme)
|
|
|
|
|
|
|
|
static uint32_t GetDPIRatio(nsIFrame* aFrame) {
|
|
|
|
return AppUnitsPerCSSPixel() / aFrame->PresContext()
|
|
|
|
->DeviceContext()
|
|
|
|
->AppUnitsPerDevPixelAtUnitFullZoom();
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool IsDateTimeResetButton(nsIFrame* aFrame) {
|
|
|
|
nsIFrame* parent = aFrame->GetParent();
|
|
|
|
if (parent && (parent = parent->GetParent()) &&
|
|
|
|
(parent = parent->GetParent())) {
|
|
|
|
nsDateTimeControlFrame* dateTimeFrame = do_QueryFrame(parent);
|
|
|
|
if (dateTimeFrame) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool IsDateTimeTextField(nsIFrame* aFrame) {
|
|
|
|
nsDateTimeControlFrame* dateTimeFrame = do_QueryFrame(aFrame);
|
|
|
|
return dateTimeFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ComputeCheckColors(const EventStates& aState,
|
|
|
|
Color& aBackgroundColor, Color& aBorderColor) {
|
|
|
|
bool isDisabled = aState.HasState(NS_EVENT_STATE_DISABLED);
|
2020-03-02 18:09:00 +00:00
|
|
|
bool isPressed = !isDisabled && aState.HasAllStates(NS_EVENT_STATE_HOVER |
|
|
|
|
NS_EVENT_STATE_ACTIVE);
|
2020-02-10 19:26:01 +00:00
|
|
|
bool isHovered = !isDisabled && aState.HasState(NS_EVENT_STATE_HOVER);
|
|
|
|
bool isChecked = aState.HasState(NS_EVENT_STATE_CHECKED);
|
|
|
|
|
|
|
|
Color fillColor = sBackgroundColor;
|
|
|
|
Color borderColor = sBorderColor;
|
|
|
|
if (isDisabled) {
|
|
|
|
if (isChecked) {
|
2020-03-02 18:09:00 +00:00
|
|
|
fillColor = borderColor = sCheckBackgroundColorDisabled;
|
2020-02-10 19:26:01 +00:00
|
|
|
} else {
|
|
|
|
fillColor = sBackgroundColor;
|
|
|
|
borderColor = sBorderColorDisabled;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (isChecked) {
|
2020-03-02 18:09:00 +00:00
|
|
|
if (isPressed) {
|
2020-02-10 19:26:01 +00:00
|
|
|
fillColor = borderColor = sCheckBackgroundActiveColor;
|
|
|
|
} else if (isHovered) {
|
|
|
|
fillColor = borderColor = sCheckBackgroundHoverColor;
|
|
|
|
} else {
|
|
|
|
fillColor = borderColor = sCheckBackgroundColor;
|
|
|
|
}
|
2020-03-02 18:09:00 +00:00
|
|
|
} else if (isPressed) {
|
2020-02-10 19:26:01 +00:00
|
|
|
fillColor = sBackgroundActiveColor;
|
|
|
|
borderColor = sBorderHoverColor;
|
|
|
|
} else if (isHovered) {
|
|
|
|
fillColor = sBackgroundColor;
|
|
|
|
borderColor = sBorderHoverColor;
|
|
|
|
} else {
|
|
|
|
fillColor = sBackgroundColor;
|
|
|
|
borderColor = sBorderColor;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
aBackgroundColor = fillColor;
|
|
|
|
aBorderColor = borderColor;
|
|
|
|
}
|
|
|
|
|
2020-02-16 16:04:31 +00:00
|
|
|
// Checkbox and radio need to preserve aspect-ratio for compat.
|
|
|
|
static Rect FixAspectRatio(const Rect& aRect) {
|
|
|
|
Rect rect(aRect);
|
|
|
|
if (rect.width == rect.height) {
|
|
|
|
return rect;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rect.width > rect.height) {
|
|
|
|
auto diff = rect.width - rect.height;
|
|
|
|
rect.width = rect.height;
|
|
|
|
rect.x += diff / 2;
|
|
|
|
} else {
|
|
|
|
auto diff = rect.height - rect.width;
|
|
|
|
rect.height = rect.width;
|
|
|
|
rect.y += diff / 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rect;
|
|
|
|
}
|
|
|
|
|
2020-03-06 02:47:59 +00:00
|
|
|
// This pushes and pops a clip rect to the draw target.
|
|
|
|
//
|
|
|
|
// This is done to reduce fuzz in places where we may have antialiasing, because
|
|
|
|
// skia is not clip-invariant: given different clips, it does not guarantee the
|
|
|
|
// same result, even if the painted content doesn't intersect the clips.
|
|
|
|
//
|
|
|
|
// This is a bit sad, overall, but...
|
|
|
|
struct MOZ_RAII AutoClipRect {
|
|
|
|
AutoClipRect(DrawTarget& aDt, const Rect& aRect) : mDt(aDt) {
|
|
|
|
mDt.PushClipRect(aRect);
|
|
|
|
}
|
|
|
|
|
|
|
|
~AutoClipRect() { mDt.PopClip(); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
DrawTarget& mDt;
|
|
|
|
};
|
|
|
|
|
2020-03-05 00:25:31 +00:00
|
|
|
static void PaintRoundedRectWithBorder(DrawTarget* aDrawTarget,
|
|
|
|
const Rect& aRect,
|
|
|
|
const Color& aBackgroundColor,
|
|
|
|
const Color& aBorderColor,
|
|
|
|
CSSCoord aBorderWidth, CSSCoord aRadius,
|
|
|
|
uint32_t aDpi) {
|
|
|
|
const LayoutDeviceCoord borderWidth(aBorderWidth * aDpi);
|
|
|
|
const LayoutDeviceCoord radius(aRadius * aDpi);
|
|
|
|
|
|
|
|
Rect rect(aRect);
|
|
|
|
// Deflate the rect by half the border width, so that the middle of the stroke
|
|
|
|
// fills exactly the area we want to fill and not more.
|
|
|
|
rect.Deflate(borderWidth * 0.5f);
|
|
|
|
|
|
|
|
RectCornerRadii radii(radius, radius, radius, radius);
|
|
|
|
RefPtr<Path> roundedRect = MakePathForRoundedRect(*aDrawTarget, rect, radii);
|
|
|
|
|
|
|
|
aDrawTarget->Fill(roundedRect, ColorPattern(ToDeviceColor(aBackgroundColor)));
|
|
|
|
aDrawTarget->Stroke(roundedRect, ColorPattern(ToDeviceColor(aBorderColor)),
|
|
|
|
StrokeOptions(borderWidth));
|
|
|
|
}
|
|
|
|
|
2020-02-10 19:26:01 +00:00
|
|
|
static void PaintCheckboxControl(DrawTarget* aDrawTarget, const Rect& aRect,
|
|
|
|
const EventStates& aState, uint32_t aDpi) {
|
2020-03-05 00:25:31 +00:00
|
|
|
const CSSCoord kBorderWidth = 2.0f;
|
|
|
|
const CSSCoord kRadius = 4.0f;
|
2020-02-10 19:26:01 +00:00
|
|
|
|
|
|
|
Color backgroundColor;
|
|
|
|
Color borderColor;
|
|
|
|
ComputeCheckColors(aState, backgroundColor, borderColor);
|
2020-03-05 00:25:31 +00:00
|
|
|
PaintRoundedRectWithBorder(aDrawTarget, aRect, backgroundColor, borderColor,
|
|
|
|
kBorderWidth, kRadius, aDpi);
|
2020-02-10 19:26:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void PaintCheckMark(DrawTarget* aDrawTarget, const Rect& aRect,
|
|
|
|
const EventStates& aState, uint32_t aDpi) {
|
|
|
|
// Points come from the coordinates on a 7X7 unit box centered at 0,0
|
|
|
|
const float checkPolygonX[] = {-2.5, -0.7, 2.5};
|
|
|
|
const float checkPolygonY[] = {-0.3, 1.7, -1.5};
|
|
|
|
const int32_t checkNumPoints = sizeof(checkPolygonX) / sizeof(float);
|
|
|
|
const int32_t checkSize = 8;
|
|
|
|
|
2020-02-16 16:04:31 +00:00
|
|
|
auto center = aRect.Center();
|
|
|
|
|
2020-02-10 19:26:01 +00:00
|
|
|
// Scale the checkmark based on the smallest dimension
|
|
|
|
nscoord paintScale = std::min(aRect.width, aRect.height) / checkSize;
|
|
|
|
RefPtr<PathBuilder> builder = aDrawTarget->CreatePathBuilder();
|
2020-02-16 16:04:31 +00:00
|
|
|
Point p = center +
|
2020-02-10 19:26:01 +00:00
|
|
|
Point(checkPolygonX[0] * paintScale, checkPolygonY[0] * paintScale);
|
|
|
|
builder->MoveTo(p);
|
|
|
|
for (int32_t polyIndex = 1; polyIndex < checkNumPoints; polyIndex++) {
|
2020-02-16 16:04:31 +00:00
|
|
|
p = center + Point(checkPolygonX[polyIndex] * paintScale,
|
|
|
|
checkPolygonY[polyIndex] * paintScale);
|
2020-02-10 19:26:01 +00:00
|
|
|
builder->LineTo(p);
|
|
|
|
}
|
|
|
|
RefPtr<Path> path = builder->Finish();
|
|
|
|
aDrawTarget->Stroke(path, ColorPattern(ToDeviceColor(sBackgroundColor)),
|
|
|
|
StrokeOptions(2.0f * aDpi));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void PaintIndeterminateMark(DrawTarget* aDrawTarget, const Rect& aRect,
|
|
|
|
const EventStates& aState) {
|
|
|
|
bool isDisabled = aState.HasState(NS_EVENT_STATE_DISABLED);
|
|
|
|
|
|
|
|
Rect rect(aRect);
|
|
|
|
rect.y += (rect.height - rect.height / 4) / 2;
|
|
|
|
rect.height /= 4;
|
|
|
|
|
|
|
|
aDrawTarget->FillRect(
|
|
|
|
rect, ColorPattern(
|
|
|
|
ToDeviceColor(isDisabled ? sDisabledColor : sBackgroundColor)));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void PaintRadioControl(DrawTarget* aDrawTarget, const Rect& aRect,
|
|
|
|
const EventStates& aState, uint32_t aDpi) {
|
2020-03-05 22:36:12 +00:00
|
|
|
const float kBorderWidth = 2.0f * aDpi;
|
|
|
|
|
2020-02-10 19:26:01 +00:00
|
|
|
RefPtr<PathBuilder> builder = aDrawTarget->CreatePathBuilder();
|
2020-03-05 22:36:12 +00:00
|
|
|
|
|
|
|
// Deflate for the same reason as PaintRoundedRectWithBorder. Note that the
|
|
|
|
// size is the diameter, so we just shrink by the border width once.
|
|
|
|
Size size(aRect.Size() - Size(kBorderWidth, kBorderWidth));
|
|
|
|
AppendEllipseToPath(builder, aRect.Center(), size);
|
2020-02-10 19:26:01 +00:00
|
|
|
RefPtr<Path> ellipse = builder->Finish();
|
|
|
|
|
|
|
|
Color backgroundColor;
|
|
|
|
Color borderColor;
|
|
|
|
ComputeCheckColors(aState, backgroundColor, borderColor);
|
|
|
|
|
|
|
|
aDrawTarget->Fill(ellipse, ColorPattern(ToDeviceColor(backgroundColor)));
|
|
|
|
aDrawTarget->Stroke(ellipse, ColorPattern(ToDeviceColor(borderColor)),
|
2020-03-05 22:36:12 +00:00
|
|
|
StrokeOptions(kBorderWidth));
|
2020-02-10 19:26:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void PaintCheckedRadioButton(DrawTarget* aDrawTarget, const Rect& aRect,
|
|
|
|
uint32_t aDpi) {
|
|
|
|
Rect rect(aRect);
|
|
|
|
rect.x += 4.5f * aDpi;
|
|
|
|
rect.width -= 9.0f * aDpi;
|
|
|
|
rect.y += 4.5f * aDpi;
|
|
|
|
rect.height -= 9.0f * aDpi;
|
|
|
|
|
|
|
|
RefPtr<PathBuilder> builder = aDrawTarget->CreatePathBuilder();
|
|
|
|
AppendEllipseToPath(builder, rect.Center(), rect.Size());
|
|
|
|
RefPtr<Path> ellipse = builder->Finish();
|
|
|
|
aDrawTarget->Fill(ellipse, ColorPattern(ToDeviceColor(sBackgroundColor)));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void PaintTextField(DrawTarget* aDrawTarget, const Rect& aRect,
|
|
|
|
const EventStates& aState, uint32_t aDpi) {
|
|
|
|
bool isDisabled = aState.HasState(NS_EVENT_STATE_DISABLED);
|
|
|
|
bool isHovered = !isDisabled && aState.HasState(NS_EVENT_STATE_HOVER);
|
|
|
|
|
2020-03-05 00:25:31 +00:00
|
|
|
const Color& backgroundColor = isDisabled ? sDisabledColor : sBackgroundColor;
|
|
|
|
const Color& borderColor = isHovered ? sBorderHoverColor : sBorderColor;
|
|
|
|
|
|
|
|
const CSSCoord kBorderWidth = 1.0f;
|
|
|
|
const CSSCoord kRadius = 4.0f;
|
|
|
|
|
|
|
|
PaintRoundedRectWithBorder(aDrawTarget, aRect, backgroundColor, borderColor,
|
|
|
|
kBorderWidth, kRadius, aDpi);
|
2020-02-10 19:26:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void PaintMenulist(DrawTarget* aDrawTarget, const Rect& aRect,
|
|
|
|
const EventStates& aState, uint32_t aDpi) {
|
|
|
|
bool isActive =
|
|
|
|
aState.HasAllStates(NS_EVENT_STATE_HOVER | NS_EVENT_STATE_ACTIVE);
|
|
|
|
bool isDisabled = aState.HasState(NS_EVENT_STATE_DISABLED);
|
|
|
|
bool isHovered = !isDisabled && aState.HasState(NS_EVENT_STATE_HOVER);
|
|
|
|
|
2020-03-05 00:25:31 +00:00
|
|
|
const Color& backgroundColor = [&] {
|
|
|
|
if (isDisabled) {
|
|
|
|
return sDisabledColor;
|
|
|
|
}
|
|
|
|
if (isActive) {
|
|
|
|
return sButtonActiveColor;
|
|
|
|
}
|
|
|
|
if (isHovered) {
|
|
|
|
return sButtonHoverColor;
|
|
|
|
}
|
|
|
|
return sButtonColor;
|
|
|
|
}();
|
2020-02-10 19:26:01 +00:00
|
|
|
|
2020-03-05 00:25:31 +00:00
|
|
|
const Color& borderColor = isHovered ? sBorderHoverColor : sBorderColor;
|
|
|
|
const CSSCoord kBorderWidth = 1.0f;
|
|
|
|
const CSSCoord kRadius = 4.0f;
|
2020-02-10 19:26:01 +00:00
|
|
|
|
2020-03-05 00:25:31 +00:00
|
|
|
PaintRoundedRectWithBorder(aDrawTarget, aRect, backgroundColor, borderColor,
|
|
|
|
kBorderWidth, kRadius, aDpi);
|
2020-02-10 19:26:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void PaintArrow(DrawTarget* aDrawTarget, const Rect& aRect,
|
|
|
|
const int32_t aArrowPolygonX[],
|
|
|
|
const int32_t aArrowPolygonY[],
|
|
|
|
const int32_t aArrowNumPoints, const int32_t aArrowSize,
|
|
|
|
const Color aFillColor, uint32_t aDpi) {
|
|
|
|
nscoord paintScale = std::min(aRect.width, aRect.height) / aArrowSize;
|
|
|
|
RefPtr<PathBuilder> builder = aDrawTarget->CreatePathBuilder();
|
|
|
|
Point p = aRect.Center() + Point(aArrowPolygonX[0] * paintScale,
|
|
|
|
aArrowPolygonY[0] * paintScale);
|
|
|
|
|
|
|
|
builder->MoveTo(p);
|
|
|
|
for (int32_t polyIndex = 1; polyIndex < aArrowNumPoints; polyIndex++) {
|
|
|
|
p = aRect.Center() + Point(aArrowPolygonX[polyIndex] * paintScale,
|
|
|
|
aArrowPolygonY[polyIndex] * paintScale);
|
|
|
|
builder->LineTo(p);
|
|
|
|
}
|
|
|
|
RefPtr<Path> path = builder->Finish();
|
|
|
|
|
|
|
|
aDrawTarget->Stroke(path, ColorPattern(ToDeviceColor(aFillColor)),
|
|
|
|
StrokeOptions(2.0f * aDpi));
|
|
|
|
}
|
|
|
|
|
2020-03-05 21:13:46 +00:00
|
|
|
static void PaintMenulistArrowButton(nsIFrame* aFrame, DrawTarget* aDrawTarget,
|
|
|
|
const Rect& aRect,
|
|
|
|
const EventStates& aState, uint32_t aDpi) {
|
2020-02-10 19:26:01 +00:00
|
|
|
bool isDisabled = aState.HasState(NS_EVENT_STATE_DISABLED);
|
2020-03-02 18:09:00 +00:00
|
|
|
bool isPressed = !isDisabled && aState.HasAllStates(NS_EVENT_STATE_HOVER |
|
|
|
|
NS_EVENT_STATE_ACTIVE);
|
2020-02-10 19:26:01 +00:00
|
|
|
bool isHovered = !isDisabled && aState.HasState(NS_EVENT_STATE_HOVER);
|
|
|
|
bool isHTML = nsNativeTheme::IsHTMLContent(aFrame);
|
|
|
|
|
|
|
|
if (!isHTML && nsNativeTheme::CheckBooleanAttr(aFrame, nsGkAtoms::open)) {
|
|
|
|
isHovered = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const int32_t arrowSize = 8;
|
|
|
|
int32_t arrowPolygonX[] = {-4, -2, 0};
|
|
|
|
int32_t arrowPolygonY[] = {-1, 1, -1};
|
|
|
|
const int32_t arrowNumPoints = sizeof(arrowPolygonX) / sizeof(int32_t);
|
|
|
|
|
|
|
|
PaintArrow(
|
|
|
|
aDrawTarget, aRect, arrowPolygonX, arrowPolygonY, arrowNumPoints,
|
|
|
|
arrowSize,
|
2020-03-02 18:09:00 +00:00
|
|
|
isPressed ? sActiveColor : isHovered ? sBorderHoverColor : sBorderColor,
|
2020-02-10 19:26:01 +00:00
|
|
|
aDpi);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void PaintSpinnerButton(DrawTarget* aDrawTarget, const Rect& aRect,
|
|
|
|
const EventStates& aState,
|
|
|
|
StyleAppearance aAppearance, uint32_t aDpi) {
|
|
|
|
bool isDisabled = aState.HasState(NS_EVENT_STATE_DISABLED);
|
2020-03-02 18:09:00 +00:00
|
|
|
bool isPressed = !isDisabled && aState.HasAllStates(NS_EVENT_STATE_HOVER |
|
|
|
|
NS_EVENT_STATE_ACTIVE);
|
2020-02-10 19:26:01 +00:00
|
|
|
bool isHovered = !isDisabled && aState.HasState(NS_EVENT_STATE_HOVER);
|
|
|
|
|
|
|
|
const int32_t arrowSize = 8;
|
|
|
|
int32_t arrowPolygonX[] = {0, 2, 4};
|
|
|
|
int32_t arrowPolygonY[] = {-3, -1, -3};
|
|
|
|
const int32_t arrowNumPoints = sizeof(arrowPolygonX) / sizeof(int32_t);
|
|
|
|
|
|
|
|
if (aAppearance == StyleAppearance::SpinnerUpbutton) {
|
|
|
|
for (int32_t i = 0; i < arrowNumPoints; i++) {
|
|
|
|
arrowPolygonY[i] *= -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PaintArrow(
|
|
|
|
aDrawTarget, aRect, arrowPolygonX, arrowPolygonY, arrowNumPoints,
|
|
|
|
arrowSize,
|
2020-03-02 18:09:00 +00:00
|
|
|
isPressed ? sActiveColor : isHovered ? sBorderHoverColor : sBorderColor,
|
2020-02-10 19:26:01 +00:00
|
|
|
aDpi);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void PaintRangeInputBackground(DrawTarget* aDrawTarget,
|
|
|
|
const Rect& aRect,
|
|
|
|
const EventStates& aState,
|
2020-03-07 09:58:30 +00:00
|
|
|
uint32_t aDpi,
|
|
|
|
bool aHorizontal) {
|
2020-02-10 19:26:01 +00:00
|
|
|
Rect rect(aRect);
|
2020-03-07 09:57:42 +00:00
|
|
|
const LayoutDeviceCoord kVerticalSize = kMinimumWidgetSize * 0.25f * aDpi;
|
2020-03-07 09:58:30 +00:00
|
|
|
|
|
|
|
if (aHorizontal) {
|
2020-03-07 09:57:42 +00:00
|
|
|
rect.y += (rect.height - kVerticalSize) / 2;
|
|
|
|
rect.height = kVerticalSize;
|
2020-03-07 09:58:30 +00:00
|
|
|
} else {
|
2020-03-07 09:57:42 +00:00
|
|
|
rect.x += (rect.width - kVerticalSize) / 2;
|
|
|
|
rect.width = kVerticalSize;
|
2020-03-07 09:58:30 +00:00
|
|
|
}
|
2020-02-10 19:26:01 +00:00
|
|
|
|
|
|
|
aDrawTarget->FillRect(
|
|
|
|
rect, ColorPattern(ToDeviceColor(sRangeInputBackgroundColor)));
|
|
|
|
aDrawTarget->StrokeRect(rect,
|
|
|
|
ColorPattern(ToDeviceColor(sButtonActiveColor)));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void PaintScrollbarthumbHorizontal(DrawTarget* aDrawTarget,
|
|
|
|
const Rect& aRect,
|
|
|
|
const EventStates& aState) {
|
|
|
|
Color thumbColor = sScrollbarThumbColor;
|
|
|
|
if (aState.HasAllStates(NS_EVENT_STATE_HOVER | NS_EVENT_STATE_ACTIVE)) {
|
|
|
|
thumbColor = sScrollbarThumbColorActive;
|
|
|
|
} else if (aState.HasState(NS_EVENT_STATE_HOVER)) {
|
|
|
|
thumbColor = sScrollbarThumbColorHover;
|
|
|
|
}
|
|
|
|
aDrawTarget->FillRect(aRect, ColorPattern(ToDeviceColor(thumbColor)));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void PaintScrollbarthumbVertical(DrawTarget* aDrawTarget,
|
|
|
|
const Rect& aRect,
|
|
|
|
const EventStates& aState) {
|
|
|
|
Color thumbColor = sScrollbarThumbColor;
|
|
|
|
if (aState.HasAllStates(NS_EVENT_STATE_HOVER | NS_EVENT_STATE_ACTIVE)) {
|
|
|
|
thumbColor = sScrollbarThumbColorActive;
|
|
|
|
} else if (aState.HasState(NS_EVENT_STATE_HOVER)) {
|
|
|
|
thumbColor = sScrollbarThumbColorHover;
|
|
|
|
}
|
|
|
|
aDrawTarget->FillRect(aRect, ColorPattern(ToDeviceColor(thumbColor)));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void PaintScrollbarHorizontal(DrawTarget* aDrawTarget,
|
|
|
|
const Rect& aRect) {
|
|
|
|
aDrawTarget->FillRect(aRect, ColorPattern(ToDeviceColor(sScrollbarColor)));
|
|
|
|
RefPtr<PathBuilder> builder = aDrawTarget->CreatePathBuilder();
|
|
|
|
builder->MoveTo(Point(aRect.x, aRect.y));
|
|
|
|
builder->LineTo(Point(aRect.x + aRect.width, aRect.y));
|
|
|
|
RefPtr<Path> path = builder->Finish();
|
|
|
|
aDrawTarget->Stroke(path, ColorPattern(ToDeviceColor(sScrollbarBorderColor)));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void PaintScrollbarVerticalAndCorner(DrawTarget* aDrawTarget,
|
|
|
|
const Rect& aRect, uint32_t aDpi) {
|
|
|
|
aDrawTarget->FillRect(aRect, ColorPattern(ToDeviceColor(sScrollbarColor)));
|
|
|
|
RefPtr<PathBuilder> builder = aDrawTarget->CreatePathBuilder();
|
|
|
|
builder->MoveTo(Point(aRect.x, aRect.y));
|
|
|
|
builder->LineTo(Point(aRect.x, aRect.y + aRect.height));
|
|
|
|
RefPtr<Path> path = builder->Finish();
|
|
|
|
aDrawTarget->Stroke(path, ColorPattern(ToDeviceColor(sScrollbarBorderColor)),
|
|
|
|
StrokeOptions(1.0f * aDpi));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void PaintScrollbarbutton(DrawTarget* aDrawTarget,
|
|
|
|
StyleAppearance aAppearance, const Rect& aRect,
|
|
|
|
const EventStates& aState, uint32_t aDpi) {
|
|
|
|
bool isActive =
|
|
|
|
aState.HasAllStates(NS_EVENT_STATE_HOVER | NS_EVENT_STATE_ACTIVE);
|
|
|
|
bool isHovered = aState.HasState(NS_EVENT_STATE_HOVER);
|
|
|
|
|
|
|
|
aDrawTarget->FillRect(
|
|
|
|
aRect, ColorPattern(
|
|
|
|
ToDeviceColor(isActive ? sScrollbarButtonActiveColor
|
|
|
|
: isHovered ? sScrollbarButtonHoverColor
|
|
|
|
: sScrollbarColor)));
|
|
|
|
|
|
|
|
// Start with Up arrow.
|
|
|
|
int32_t arrowPolygonX[] = {3, 0, -3};
|
|
|
|
int32_t arrowPolygonY[] = {2, -1, 2};
|
|
|
|
const int32_t arrowNumPoints = sizeof(arrowPolygonX) / sizeof(int32_t);
|
|
|
|
const int32_t arrowSize = 14;
|
|
|
|
|
|
|
|
switch (aAppearance) {
|
|
|
|
case StyleAppearance::ScrollbarbuttonUp:
|
|
|
|
break;
|
|
|
|
case StyleAppearance::ScrollbarbuttonDown:
|
|
|
|
for (int32_t i = 0; i < arrowNumPoints; i++) {
|
|
|
|
arrowPolygonY[i] *= -1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case StyleAppearance::ScrollbarbuttonLeft:
|
|
|
|
for (int32_t i = 0; i < arrowNumPoints; i++) {
|
|
|
|
int32_t temp = arrowPolygonX[i];
|
|
|
|
arrowPolygonX[i] = arrowPolygonY[i];
|
|
|
|
arrowPolygonY[i] = temp;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case StyleAppearance::ScrollbarbuttonRight:
|
|
|
|
for (int32_t i = 0; i < arrowNumPoints; i++) {
|
|
|
|
int32_t temp = arrowPolygonX[i];
|
|
|
|
arrowPolygonX[i] = arrowPolygonY[i] * -1;
|
|
|
|
arrowPolygonY[i] = temp;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
PaintArrow(aDrawTarget, aRect, arrowPolygonX, arrowPolygonY, arrowNumPoints,
|
|
|
|
arrowSize,
|
|
|
|
isActive
|
|
|
|
? sScrollbarArrowColorActive
|
|
|
|
: isHovered ? sScrollbarArrowColorHover : sScrollbarArrowColor,
|
|
|
|
aDpi);
|
|
|
|
|
|
|
|
RefPtr<PathBuilder> builder = aDrawTarget->CreatePathBuilder();
|
|
|
|
builder->MoveTo(Point(aRect.x, aRect.y));
|
|
|
|
if (aAppearance == StyleAppearance::ScrollbarbuttonUp ||
|
|
|
|
aAppearance == StyleAppearance::ScrollbarbuttonDown) {
|
|
|
|
builder->LineTo(Point(aRect.x, aRect.y + aRect.height));
|
|
|
|
} else {
|
|
|
|
builder->LineTo(Point(aRect.x + aRect.width, aRect.y));
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<Path> path = builder->Finish();
|
|
|
|
aDrawTarget->Stroke(path, ColorPattern(ToDeviceColor(sScrollbarBorderColor)),
|
|
|
|
StrokeOptions(1.0f * aDpi));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void PaintButton(nsIFrame* aFrame, DrawTarget* aDrawTarget,
|
|
|
|
const Rect& aRect, const EventStates& aState,
|
|
|
|
uint32_t aDpi) {
|
|
|
|
bool isActive =
|
|
|
|
aState.HasAllStates(NS_EVENT_STATE_HOVER | NS_EVENT_STATE_ACTIVE);
|
|
|
|
bool isDisabled = aState.HasState(NS_EVENT_STATE_DISABLED);
|
|
|
|
bool isHovered = !isDisabled && aState.HasState(NS_EVENT_STATE_HOVER);
|
|
|
|
|
2020-03-05 00:25:31 +00:00
|
|
|
const Color& backgroundColor = [&] {
|
|
|
|
if (isDisabled) {
|
|
|
|
return sDisabledColor;
|
|
|
|
}
|
|
|
|
if (IsDateTimeResetButton(aFrame)) {
|
|
|
|
return sWhiteColor;
|
|
|
|
}
|
|
|
|
if (isActive) {
|
|
|
|
return sButtonActiveColor;
|
|
|
|
}
|
|
|
|
if (isHovered) {
|
|
|
|
return sButtonHoverColor;
|
|
|
|
}
|
|
|
|
return sButtonColor;
|
|
|
|
}();
|
2020-02-10 19:26:01 +00:00
|
|
|
|
2020-03-05 00:25:31 +00:00
|
|
|
const Color& borderColor = isHovered ? sBorderHoverColor : sBorderColor;
|
|
|
|
|
|
|
|
const CSSCoord kBorderWidth = 1.0f;
|
|
|
|
const CSSCoord kRadius = 4.0f;
|
2020-02-10 19:26:01 +00:00
|
|
|
|
2020-03-05 00:25:31 +00:00
|
|
|
PaintRoundedRectWithBorder(aDrawTarget, aRect, backgroundColor, borderColor,
|
|
|
|
kBorderWidth, kRadius, aDpi);
|
2020-02-10 19:26:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNativeBasicTheme::DrawWidgetBackground(gfxContext* aContext, nsIFrame* aFrame,
|
|
|
|
StyleAppearance aAppearance,
|
|
|
|
const nsRect& aRect,
|
2020-03-05 00:25:31 +00:00
|
|
|
const nsRect& /* aDirtyRect */) {
|
2020-02-10 19:26:01 +00:00
|
|
|
DrawTarget* dt = aContext->GetDrawTarget();
|
|
|
|
const nscoord twipsPerPixel = aFrame->PresContext()->AppUnitsPerDevPixel();
|
|
|
|
EventStates eventState = GetContentState(aFrame, aAppearance);
|
|
|
|
|
2020-03-05 14:43:14 +00:00
|
|
|
Rect devPxRect = NSRectToSnappedRect(aRect, twipsPerPixel, *dt);
|
2020-03-06 02:47:59 +00:00
|
|
|
AutoClipRect clip(*dt, devPxRect);
|
2020-03-05 00:25:31 +00:00
|
|
|
|
2020-03-05 21:13:46 +00:00
|
|
|
if (aAppearance == StyleAppearance::MozMenulistArrowButton) {
|
2020-02-10 19:26:01 +00:00
|
|
|
bool isHTML = IsHTMLContent(aFrame);
|
|
|
|
nsIFrame* parentFrame = aFrame->GetParent();
|
|
|
|
bool isMenulist = !isHTML && parentFrame->IsMenuFrame();
|
|
|
|
// HTML select and XUL menulist dropdown buttons get state from the
|
|
|
|
// parent.
|
|
|
|
if (isHTML || isMenulist) {
|
|
|
|
aFrame = parentFrame;
|
|
|
|
eventState = GetContentState(parentFrame, aAppearance);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t dpi = GetDPIRatio(aFrame);
|
|
|
|
|
|
|
|
switch (aAppearance) {
|
2020-02-16 16:04:31 +00:00
|
|
|
case StyleAppearance::Radio: {
|
|
|
|
auto rect = FixAspectRatio(devPxRect);
|
|
|
|
PaintRadioControl(dt, rect, eventState, dpi);
|
2020-02-10 19:26:01 +00:00
|
|
|
if (IsSelected(aFrame)) {
|
2020-02-16 16:04:31 +00:00
|
|
|
PaintCheckedRadioButton(dt, rect, dpi);
|
2020-02-10 19:26:01 +00:00
|
|
|
}
|
|
|
|
break;
|
2020-02-16 16:04:31 +00:00
|
|
|
}
|
|
|
|
case StyleAppearance::Checkbox: {
|
|
|
|
auto rect = FixAspectRatio(devPxRect);
|
|
|
|
PaintCheckboxControl(dt, rect, eventState, dpi);
|
2020-02-10 19:26:01 +00:00
|
|
|
if (IsChecked(aFrame)) {
|
2020-02-16 16:04:31 +00:00
|
|
|
PaintCheckMark(dt, rect, eventState, dpi);
|
2020-02-10 19:26:01 +00:00
|
|
|
}
|
|
|
|
if (GetIndeterminate(aFrame)) {
|
2020-02-16 16:04:31 +00:00
|
|
|
PaintIndeterminateMark(dt, rect, eventState);
|
2020-02-10 19:26:01 +00:00
|
|
|
}
|
|
|
|
break;
|
2020-02-16 16:04:31 +00:00
|
|
|
}
|
2020-02-10 19:26:01 +00:00
|
|
|
case StyleAppearance::Textarea:
|
|
|
|
case StyleAppearance::Textfield:
|
|
|
|
case StyleAppearance::NumberInput:
|
|
|
|
PaintTextField(dt, devPxRect, eventState, dpi);
|
|
|
|
break;
|
|
|
|
case StyleAppearance::Listbox:
|
|
|
|
case StyleAppearance::Menulist:
|
2020-03-05 20:45:40 +00:00
|
|
|
case StyleAppearance::MenulistButton:
|
2020-02-10 19:26:01 +00:00
|
|
|
case StyleAppearance::MenulistTextfield:
|
|
|
|
PaintMenulist(dt, devPxRect, eventState, dpi);
|
|
|
|
break;
|
2020-03-05 21:13:46 +00:00
|
|
|
case StyleAppearance::MozMenulistArrowButton:
|
|
|
|
PaintMenulistArrowButton(aFrame, dt, devPxRect, eventState, dpi);
|
2020-02-10 19:26:01 +00:00
|
|
|
break;
|
|
|
|
case StyleAppearance::SpinnerUpbutton:
|
|
|
|
case StyleAppearance::SpinnerDownbutton:
|
|
|
|
PaintSpinnerButton(dt, devPxRect, eventState, aAppearance, dpi);
|
|
|
|
break;
|
|
|
|
case StyleAppearance::Range:
|
2020-03-07 09:58:30 +00:00
|
|
|
PaintRangeInputBackground(dt, devPxRect, eventState, dpi, IsRangeHorizontal(aFrame));
|
2020-02-10 19:26:01 +00:00
|
|
|
break;
|
|
|
|
case StyleAppearance::RangeThumb:
|
|
|
|
// TODO: Paint Range Thumb
|
|
|
|
break;
|
|
|
|
case StyleAppearance::ScrollbarthumbHorizontal:
|
|
|
|
PaintScrollbarthumbHorizontal(dt, devPxRect, eventState);
|
|
|
|
break;
|
|
|
|
case StyleAppearance::ScrollbarthumbVertical:
|
|
|
|
PaintScrollbarthumbVertical(dt, devPxRect, eventState);
|
|
|
|
break;
|
|
|
|
case StyleAppearance::ScrollbarHorizontal:
|
|
|
|
PaintScrollbarHorizontal(dt, devPxRect);
|
|
|
|
break;
|
|
|
|
case StyleAppearance::ScrollbarVertical:
|
|
|
|
case StyleAppearance::Scrollcorner:
|
|
|
|
PaintScrollbarVerticalAndCorner(dt, devPxRect, dpi);
|
|
|
|
break;
|
|
|
|
case StyleAppearance::ScrollbarbuttonUp:
|
|
|
|
case StyleAppearance::ScrollbarbuttonDown:
|
|
|
|
case StyleAppearance::ScrollbarbuttonLeft:
|
|
|
|
case StyleAppearance::ScrollbarbuttonRight:
|
|
|
|
PaintScrollbarbutton(dt, aAppearance, devPxRect, eventState, dpi);
|
|
|
|
break;
|
|
|
|
case StyleAppearance::Button:
|
|
|
|
PaintButton(aFrame, dt, devPxRect, eventState, dpi);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
MOZ_ASSERT_UNREACHABLE(
|
|
|
|
"Should not get here with a widget type we don't support.");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*bool
|
|
|
|
nsNativeBasicTheme::CreateWebRenderCommandsForWidget(mozilla::wr::DisplayListBuilder&
|
|
|
|
aBuilder, mozilla::wr::IpcResourceUpdateQueue& aResources, const
|
|
|
|
mozilla::layers::StackingContextHelper& aSc,
|
|
|
|
mozilla::layers::RenderRootStateManager*
|
|
|
|
aManager, nsIFrame* aFrame, StyleAppearance aAppearance, const nsRect& aRect) {
|
|
|
|
}*/
|
|
|
|
|
|
|
|
LayoutDeviceIntMargin nsNativeBasicTheme::GetWidgetBorder(
|
|
|
|
nsDeviceContext* aContext, nsIFrame* aFrame, StyleAppearance aAppearance) {
|
|
|
|
return LayoutDeviceIntMargin();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool nsNativeBasicTheme::GetWidgetPadding(nsDeviceContext* aContext,
|
|
|
|
nsIFrame* aFrame,
|
|
|
|
StyleAppearance aAppearance,
|
|
|
|
LayoutDeviceIntMargin* aResult) {
|
2020-02-14 02:20:39 +00:00
|
|
|
if (aAppearance == StyleAppearance::Menulist ||
|
|
|
|
aAppearance == StyleAppearance::MenulistTextfield ||
|
|
|
|
aAppearance == StyleAppearance::NumberInput ||
|
|
|
|
aAppearance == StyleAppearance::Textarea ||
|
|
|
|
aAppearance == StyleAppearance::Textfield) {
|
|
|
|
// If we have author-specified padding for these elements, don't do the
|
|
|
|
// fixups below.
|
|
|
|
if (aFrame->PresContext()->HasAuthorSpecifiedRules(
|
|
|
|
aFrame, NS_AUTHOR_SPECIFIED_PADDING)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-10 19:26:01 +00:00
|
|
|
uint32_t dpi = GetDPIRatio(aFrame);
|
|
|
|
switch (aAppearance) {
|
|
|
|
// Radios and checkboxes return a fixed size in GetMinimumWidgetSize
|
|
|
|
// and have a meaningful baseline, so they can't have
|
|
|
|
// author-specified padding.
|
|
|
|
case StyleAppearance::Radio:
|
|
|
|
case StyleAppearance::Checkbox:
|
2020-03-05 21:13:46 +00:00
|
|
|
case StyleAppearance::MozMenulistArrowButton:
|
2020-02-10 19:26:01 +00:00
|
|
|
aResult->SizeTo(0, 0, 0, 0);
|
|
|
|
return true;
|
|
|
|
case StyleAppearance::Textarea:
|
|
|
|
case StyleAppearance::Listbox:
|
|
|
|
case StyleAppearance::Menulist:
|
2020-03-05 20:45:40 +00:00
|
|
|
case StyleAppearance::MenulistButton:
|
2020-02-10 19:26:01 +00:00
|
|
|
case StyleAppearance::MenulistTextfield:
|
|
|
|
case StyleAppearance::NumberInput:
|
|
|
|
aResult->SizeTo(7 * dpi, 8 * dpi, 7 * dpi, 8 * dpi);
|
|
|
|
return true;
|
|
|
|
case StyleAppearance::Button:
|
|
|
|
aResult->SizeTo(7 * dpi, 22 * dpi, 7 * dpi, 22 * dpi);
|
|
|
|
return true;
|
|
|
|
case StyleAppearance::Textfield:
|
|
|
|
if (IsDateTimeTextField(aFrame)) {
|
|
|
|
aResult->SizeTo(8 * dpi, 8 * dpi, 6 * dpi, 8 * dpi);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
aResult->SizeTo(7 * dpi, 8 * dpi, 7 * dpi, 8 * dpi);
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool nsNativeBasicTheme::GetWidgetOverflow(nsDeviceContext* aContext,
|
|
|
|
nsIFrame* aFrame,
|
|
|
|
StyleAppearance aAppearance,
|
|
|
|
nsRect* aOverflowRect) {
|
2020-03-05 19:48:56 +00:00
|
|
|
// TODO(bug 1620360): This should return non-zero for
|
|
|
|
// StyleAppearance::FocusOutline, if we implement outline-style: auto.
|
2020-02-10 19:26:01 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNativeBasicTheme::GetMinimumWidgetSize(nsPresContext* aPresContext,
|
|
|
|
nsIFrame* aFrame,
|
|
|
|
StyleAppearance aAppearance,
|
2020-02-16 16:04:31 +00:00
|
|
|
LayoutDeviceIntSize* aResult,
|
2020-02-10 19:26:01 +00:00
|
|
|
bool* aIsOverridable) {
|
2020-03-07 09:57:42 +00:00
|
|
|
aResult->width = aResult->height =
|
|
|
|
static_cast<uint32_t>(kMinimumWidgetSize) * GetDPIRatio(aFrame);
|
2020-02-10 19:26:01 +00:00
|
|
|
*aIsOverridable = true;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsITheme::Transparency nsNativeBasicTheme::GetWidgetTransparency(
|
|
|
|
nsIFrame* aFrame, StyleAppearance aAppearance) {
|
|
|
|
return eUnknownTransparency;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNativeBasicTheme::WidgetStateChanged(nsIFrame* aFrame,
|
|
|
|
StyleAppearance aAppearance,
|
|
|
|
nsAtom* aAttribute, bool* aShouldRepaint,
|
|
|
|
const nsAttrValue* aOldValue) {
|
|
|
|
if (!aAttribute) {
|
|
|
|
// Hover/focus/active changed. Always repaint.
|
|
|
|
*aShouldRepaint = true;
|
|
|
|
} else {
|
|
|
|
// Check the attribute to see if it's relevant.
|
|
|
|
// disabled, checked, dlgtype, default, etc.
|
|
|
|
*aShouldRepaint = false;
|
|
|
|
if ((aAttribute == nsGkAtoms::disabled) ||
|
|
|
|
(aAttribute == nsGkAtoms::checked) ||
|
|
|
|
(aAttribute == nsGkAtoms::selected) ||
|
|
|
|
(aAttribute == nsGkAtoms::visuallyselected) ||
|
|
|
|
(aAttribute == nsGkAtoms::menuactive) ||
|
|
|
|
(aAttribute == nsGkAtoms::sortDirection) ||
|
|
|
|
(aAttribute == nsGkAtoms::focused) ||
|
|
|
|
(aAttribute == nsGkAtoms::_default) ||
|
|
|
|
(aAttribute == nsGkAtoms::open) || (aAttribute == nsGkAtoms::hover)) {
|
|
|
|
*aShouldRepaint = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNativeBasicTheme::ThemeChanged() { return NS_OK; }
|
|
|
|
|
2020-03-05 19:48:56 +00:00
|
|
|
bool nsNativeBasicTheme::WidgetAppearanceDependsOnWindowFocus(StyleAppearance) {
|
|
|
|
return false;
|
2020-02-10 19:26:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsITheme::ThemeGeometryType nsNativeBasicTheme::ThemeGeometryTypeForWidget(
|
|
|
|
nsIFrame* aFrame, StyleAppearance aAppearance) {
|
|
|
|
return eThemeGeometryTypeUnknown;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool nsNativeBasicTheme::ThemeSupportsWidget(nsPresContext* aPresContext,
|
|
|
|
nsIFrame* aFrame,
|
|
|
|
StyleAppearance aAppearance) {
|
2020-02-12 19:38:35 +00:00
|
|
|
if (IsWidgetScrollbarPart(aAppearance)) {
|
|
|
|
const auto* style = nsLayoutUtils::StyleForScrollbar(aFrame);
|
|
|
|
// We don't currently handle custom scrollbars on nsNativeBasicTheme. We
|
|
|
|
// could, potentially.
|
|
|
|
if (style->StyleUI()->HasCustomScrollbars() ||
|
|
|
|
style->StyleUIReset()->mScrollbarWidth == StyleScrollbarWidth::Thin) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-10 19:26:01 +00:00
|
|
|
switch (aAppearance) {
|
|
|
|
case StyleAppearance::Radio:
|
|
|
|
case StyleAppearance::Checkbox:
|
|
|
|
case StyleAppearance::Textarea:
|
|
|
|
case StyleAppearance::Textfield:
|
|
|
|
case StyleAppearance::Range:
|
|
|
|
/*case StyleAppearance::RangeThumb:*/
|
|
|
|
case StyleAppearance::ScrollbarbuttonUp:
|
|
|
|
case StyleAppearance::ScrollbarbuttonDown:
|
|
|
|
case StyleAppearance::ScrollbarbuttonLeft:
|
|
|
|
case StyleAppearance::ScrollbarbuttonRight:
|
|
|
|
case StyleAppearance::ScrollbarthumbHorizontal:
|
|
|
|
case StyleAppearance::ScrollbarthumbVertical:
|
|
|
|
case StyleAppearance::ScrollbarHorizontal:
|
|
|
|
case StyleAppearance::ScrollbarVertical:
|
|
|
|
case StyleAppearance::Scrollcorner:
|
|
|
|
case StyleAppearance::Button:
|
|
|
|
case StyleAppearance::Listbox:
|
|
|
|
case StyleAppearance::Menulist:
|
2020-02-19 14:48:43 +00:00
|
|
|
case StyleAppearance::MenulistButton:
|
2020-02-10 19:26:01 +00:00
|
|
|
case StyleAppearance::MenulistTextfield:
|
|
|
|
case StyleAppearance::NumberInput:
|
2020-03-05 21:13:46 +00:00
|
|
|
case StyleAppearance::MozMenulistArrowButton:
|
2020-02-10 19:26:01 +00:00
|
|
|
case StyleAppearance::SpinnerUpbutton:
|
|
|
|
case StyleAppearance::SpinnerDownbutton:
|
|
|
|
return !IsWidgetStyled(aPresContext, aFrame, aAppearance);
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool nsNativeBasicTheme::WidgetIsContainer(StyleAppearance aAppearance) {
|
|
|
|
switch (aAppearance) {
|
2020-03-05 21:13:46 +00:00
|
|
|
case StyleAppearance::MozMenulistArrowButton:
|
2020-02-10 19:26:01 +00:00
|
|
|
case StyleAppearance::Radio:
|
|
|
|
case StyleAppearance::Checkbox:
|
|
|
|
return false;
|
|
|
|
default:
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool nsNativeBasicTheme::ThemeDrawsFocusForWidget(StyleAppearance aAppearance) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool nsNativeBasicTheme::ThemeNeedsComboboxDropmarker() { return true; }
|
2020-03-03 19:46:41 +00:00
|
|
|
|
|
|
|
already_AddRefed<nsITheme> do_GetBasicNativeThemeDoNotUseDirectly() {
|
|
|
|
static StaticRefPtr<nsITheme> gInstance;
|
|
|
|
if (MOZ_UNLIKELY(!gInstance)) {
|
|
|
|
gInstance = new nsNativeBasicTheme();
|
|
|
|
ClearOnShutdown(&gInstance);
|
|
|
|
}
|
|
|
|
return do_AddRef(gInstance);
|
|
|
|
}
|