1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7 /* rendering object for HTML <wbr> elements */
8
9 #include "nsFrame.h"
10
11 using namespace mozilla;
12
13 namespace mozilla {
14
15 class WBRFrame final : public nsFrame {
16 public:
17 NS_DECL_FRAMEARENA_HELPERS(WBRFrame)
18
19 friend nsIFrame* ::NS_NewWBRFrame(mozilla::PresShell* aPresShell,
20 ComputedStyle* aStyle);
21
22 virtual FrameSearchResult PeekOffsetNoAmount(bool aForward,
23 int32_t* aOffset) override;
24 virtual FrameSearchResult PeekOffsetCharacter(
25 bool aForward, int32_t* aOffset,
26 PeekOffsetCharacterOptions aOptions =
27 PeekOffsetCharacterOptions()) override;
28 virtual FrameSearchResult PeekOffsetWord(
29 bool aForward, bool aWordSelectEatSpace, bool aIsKeyboardSelect,
30 int32_t* aOffset, PeekWordState* aState, bool aTrimSpaces) override;
31
32 protected:
WBRFrame(ComputedStyle * aStyle,nsPresContext * aPresContext)33 explicit WBRFrame(ComputedStyle* aStyle, nsPresContext* aPresContext)
34 : nsFrame(aStyle, aPresContext, kClassID) {}
35 };
36
37 } // namespace mozilla
38
NS_NewWBRFrame(mozilla::PresShell * aPresShell,ComputedStyle * aStyle)39 nsIFrame* NS_NewWBRFrame(mozilla::PresShell* aPresShell,
40 ComputedStyle* aStyle) {
41 return new (aPresShell) WBRFrame(aStyle, aPresShell->GetPresContext());
42 }
43
NS_IMPL_FRAMEARENA_HELPERS(WBRFrame)44 NS_IMPL_FRAMEARENA_HELPERS(WBRFrame)
45
46 nsIFrame::FrameSearchResult WBRFrame::PeekOffsetNoAmount(bool aForward,
47 int32_t* aOffset) {
48 NS_ASSERTION(aOffset && *aOffset <= 1, "aOffset out of range");
49 // WBR frames can not contain text or non-rendered whitespace
50 return CONTINUE;
51 }
52
PeekOffsetCharacter(bool aForward,int32_t * aOffset,PeekOffsetCharacterOptions aOptions)53 nsIFrame::FrameSearchResult WBRFrame::PeekOffsetCharacter(
54 bool aForward, int32_t* aOffset, PeekOffsetCharacterOptions aOptions) {
55 NS_ASSERTION(aOffset && *aOffset <= 1, "aOffset out of range");
56 // WBR frames can not contain characters
57 return CONTINUE;
58 }
59
PeekOffsetWord(bool aForward,bool aWordSelectEatSpace,bool aIsKeyboardSelect,int32_t * aOffset,PeekWordState * aState,bool aTrimSpaces)60 nsIFrame::FrameSearchResult WBRFrame::PeekOffsetWord(
61 bool aForward, bool aWordSelectEatSpace, bool aIsKeyboardSelect,
62 int32_t* aOffset, PeekWordState* aState, bool aTrimSpaces) {
63 NS_ASSERTION(aOffset && *aOffset <= 1, "aOffset out of range");
64 // WBR frames can never contain text so we'll never find a word inside them
65 return CONTINUE;
66 }