2023-03-05 22:24:10 +00: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: */
|
|
|
|
/* 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/. */
|
|
|
|
|
|
|
|
#ifndef nsTextPaintStyle_h__
|
|
|
|
#define nsTextPaintStyle_h__
|
|
|
|
|
|
|
|
#include "mozilla/Attributes.h"
|
|
|
|
#include "mozilla/ComputedStyle.h"
|
2024-01-09 18:06:12 +00:00
|
|
|
#include "mozilla/EnumeratedArray.h"
|
2023-03-05 22:24:10 +00:00
|
|
|
#include "mozilla/Span.h"
|
|
|
|
|
2023-08-18 18:43:27 +00:00
|
|
|
#include "nsAtomHashKeys.h"
|
2023-03-05 22:24:10 +00:00
|
|
|
#include "nsISelectionController.h"
|
|
|
|
#include "nsTHashMap.h"
|
|
|
|
|
|
|
|
class nsTextFrame;
|
|
|
|
class nsPresContext;
|
|
|
|
|
2023-05-12 23:33:12 +00:00
|
|
|
namespace mozilla {
|
|
|
|
enum class StyleTextDecorationStyle : uint8_t;
|
|
|
|
}
|
|
|
|
|
2023-03-05 22:24:10 +00:00
|
|
|
/**
|
|
|
|
* This helper object computes colors used for painting, and also IME
|
|
|
|
* underline information. The data is computed lazily and cached as necessary.
|
|
|
|
* These live for just the duration of one paint operation.
|
|
|
|
*/
|
|
|
|
class MOZ_STACK_CLASS nsTextPaintStyle {
|
|
|
|
using ComputedStyle = mozilla::ComputedStyle;
|
|
|
|
using SelectionType = mozilla::SelectionType;
|
|
|
|
using StyleTextDecorationStyle = mozilla::StyleTextDecorationStyle;
|
|
|
|
using StyleSimpleShadow = mozilla::StyleSimpleShadow;
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit nsTextPaintStyle(nsTextFrame* aFrame);
|
|
|
|
|
|
|
|
void SetResolveColors(bool aResolveColors) {
|
|
|
|
mResolveColors = aResolveColors;
|
|
|
|
}
|
|
|
|
|
|
|
|
nscolor GetTextColor();
|
|
|
|
|
|
|
|
// SVG text has its own painting process, so we should never get its stroke
|
|
|
|
// property from here.
|
|
|
|
nscolor GetWebkitTextStrokeColor();
|
|
|
|
float GetWebkitTextStrokeWidth();
|
|
|
|
|
2024-01-09 18:06:12 +00:00
|
|
|
// Index used to look up styles for different types of selection.
|
|
|
|
enum class SelectionStyleIndex : uint8_t {
|
|
|
|
RawInput = 0,
|
|
|
|
SelRawText,
|
|
|
|
ConvText,
|
|
|
|
SelConvText,
|
|
|
|
SpellChecker,
|
|
|
|
// Not an actual enum value; used to size the array of styles.
|
|
|
|
Count,
|
|
|
|
};
|
|
|
|
|
2023-03-05 22:24:10 +00:00
|
|
|
/**
|
|
|
|
* Compute the colors for normally-selected text. Returns false if
|
|
|
|
* the normal selection is not being displayed.
|
|
|
|
*/
|
|
|
|
bool GetSelectionColors(nscolor* aForeColor, nscolor* aBackColor);
|
|
|
|
void GetHighlightColors(nscolor* aForeColor, nscolor* aBackColor);
|
2024-04-04 14:39:32 +00:00
|
|
|
void GetTargetTextColors(nscolor* aForeColor, nscolor* aBackColor);
|
2023-03-05 22:24:10 +00:00
|
|
|
// Computes colors for custom highlights.
|
|
|
|
// Returns false if there are no rules associated with `aHighlightName`.
|
2023-07-31 13:47:55 +00:00
|
|
|
bool GetCustomHighlightTextColor(nsAtom* aHighlightName, nscolor* aForeColor);
|
|
|
|
bool GetCustomHighlightBackgroundColor(nsAtom* aHighlightName,
|
2023-06-23 15:22:44 +00:00
|
|
|
nscolor* aBackColor);
|
2023-03-05 22:24:10 +00:00
|
|
|
void GetURLSecondaryColor(nscolor* aForeColor);
|
2024-01-09 18:06:12 +00:00
|
|
|
void GetIMESelectionColors(SelectionStyleIndex aIndex, nscolor* aForeColor,
|
2023-03-05 22:24:10 +00:00
|
|
|
nscolor* aBackColor);
|
|
|
|
// if this returns false, we don't need to draw underline.
|
2024-01-09 18:06:12 +00:00
|
|
|
bool GetSelectionUnderlineForPaint(SelectionStyleIndex aIndex,
|
|
|
|
nscolor* aLineColor, float* aRelativeSize,
|
2023-03-05 22:24:10 +00:00
|
|
|
StyleTextDecorationStyle* aStyle);
|
|
|
|
|
|
|
|
// if this returns false, we don't need to draw underline.
|
2024-01-09 18:06:12 +00:00
|
|
|
static bool GetSelectionUnderline(nsIFrame*, SelectionStyleIndex aIndex,
|
2023-03-05 22:24:10 +00:00
|
|
|
nscolor* aLineColor, float* aRelativeSize,
|
|
|
|
StyleTextDecorationStyle* aStyle);
|
|
|
|
|
|
|
|
// if this returns false, no text-shadow was specified for the selection
|
|
|
|
// and the *aShadow parameter was not modified.
|
|
|
|
bool GetSelectionShadow(mozilla::Span<const StyleSimpleShadow>* aShadows);
|
|
|
|
|
|
|
|
nsPresContext* PresContext() const { return mPresContext; }
|
|
|
|
|
2024-01-09 18:06:12 +00:00
|
|
|
static SelectionStyleIndex GetUnderlineStyleIndexForSelectionType(
|
2023-03-05 22:24:10 +00:00
|
|
|
SelectionType aSelectionType) {
|
|
|
|
switch (aSelectionType) {
|
|
|
|
case SelectionType::eIMERawClause:
|
2024-01-09 18:06:12 +00:00
|
|
|
return SelectionStyleIndex::RawInput;
|
2023-03-05 22:24:10 +00:00
|
|
|
case SelectionType::eIMESelectedRawClause:
|
2024-01-09 18:06:12 +00:00
|
|
|
return SelectionStyleIndex::SelRawText;
|
2023-03-05 22:24:10 +00:00
|
|
|
case SelectionType::eIMEConvertedClause:
|
2024-01-09 18:06:12 +00:00
|
|
|
return SelectionStyleIndex::ConvText;
|
2023-03-05 22:24:10 +00:00
|
|
|
case SelectionType::eIMESelectedClause:
|
2024-01-09 18:06:12 +00:00
|
|
|
return SelectionStyleIndex::SelConvText;
|
2023-03-05 22:24:10 +00:00
|
|
|
case SelectionType::eSpellCheck:
|
2024-01-09 18:06:12 +00:00
|
|
|
return SelectionStyleIndex::SpellChecker;
|
2023-03-05 22:24:10 +00:00
|
|
|
default:
|
|
|
|
NS_WARNING("non-IME selection type");
|
2024-01-09 18:06:12 +00:00
|
|
|
return SelectionStyleIndex::RawInput;
|
2023-03-05 22:24:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nscolor GetSystemFieldForegroundColor();
|
|
|
|
nscolor GetSystemFieldBackgroundColor();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
nsTextFrame* mFrame;
|
|
|
|
nsPresContext* mPresContext;
|
|
|
|
bool mInitCommonColors;
|
|
|
|
bool mInitSelectionColorsAndShadow;
|
|
|
|
bool mResolveColors;
|
|
|
|
|
|
|
|
// Selection data
|
|
|
|
|
|
|
|
nscolor mSelectionTextColor;
|
|
|
|
nscolor mSelectionBGColor;
|
|
|
|
RefPtr<ComputedStyle> mSelectionPseudoStyle;
|
2023-08-18 18:43:27 +00:00
|
|
|
nsTHashMap<RefPtr<nsAtom>, RefPtr<ComputedStyle>>
|
2023-03-05 22:24:10 +00:00
|
|
|
mCustomHighlightPseudoStyles;
|
|
|
|
|
|
|
|
// Common data
|
|
|
|
|
|
|
|
int32_t mSufficientContrast;
|
|
|
|
nscolor mFrameBackgroundColor;
|
|
|
|
nscolor mSystemFieldForegroundColor;
|
|
|
|
nscolor mSystemFieldBackgroundColor;
|
|
|
|
|
|
|
|
// selection colors and underline info, the colors are resolved colors if
|
|
|
|
// mResolveColors is true (which is the default), i.e., the foreground color
|
|
|
|
// and background color are swapped if it's needed. And also line color will
|
|
|
|
// be resolved from them.
|
|
|
|
struct nsSelectionStyle {
|
|
|
|
nscolor mTextColor;
|
|
|
|
nscolor mBGColor;
|
|
|
|
nscolor mUnderlineColor;
|
|
|
|
StyleTextDecorationStyle mUnderlineStyle;
|
|
|
|
float mUnderlineRelativeSize;
|
|
|
|
};
|
2024-03-02 07:50:19 +00:00
|
|
|
mozilla::EnumeratedArray<SelectionStyleIndex,
|
|
|
|
mozilla::Maybe<nsSelectionStyle>,
|
2024-03-02 07:50:19 +00:00
|
|
|
size_t(SelectionStyleIndex::Count)>
|
2024-01-09 18:06:12 +00:00
|
|
|
mSelectionStyle;
|
2023-03-05 22:24:10 +00:00
|
|
|
|
|
|
|
// Color initializations
|
|
|
|
void InitCommonColors();
|
|
|
|
bool InitSelectionColorsAndShadow();
|
|
|
|
|
2024-01-09 18:06:12 +00:00
|
|
|
nsSelectionStyle* SelectionStyle(SelectionStyleIndex aIndex);
|
|
|
|
nsSelectionStyle InitSelectionStyle(SelectionStyleIndex aIndex);
|
2023-03-05 22:24:10 +00:00
|
|
|
|
|
|
|
// Ensures sufficient contrast between the frame background color and the
|
|
|
|
// selection background color, and swaps the selection text and background
|
|
|
|
// colors accordingly.
|
|
|
|
bool EnsureSufficientContrast(nscolor* aForeColor, nscolor* aBackColor);
|
|
|
|
|
|
|
|
nscolor GetResolvedForeColor(nscolor aColor, nscolor aDefaultForeColor,
|
|
|
|
nscolor aBackColor);
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // nsTextPaintStyle_h__
|