blob: 710beb7f0562e09a6e304f4c77d0d1c0052827a7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_TEXT_WRITING_DIRECTION_MODE_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_TEXT_WRITING_DIRECTION_MODE_H_
#include "third_party/blink/renderer/platform/platform_export.h"
#include "third_party/blink/renderer/platform/text/text_direction.h"
#include "third_party/blink/renderer/platform/text/writing_mode.h"
#include "third_party/blink/renderer/platform/wtf/allocator/allocator.h"
namespace blink {
// This class packs |WritingMode| and |TextDirection|, two enums that are often
// used and passed around together, into the size of the minimum memory align.
class PLATFORM_EXPORT WritingDirectionMode {
DISALLOW_NEW();
public:
WritingDirectionMode(WritingMode writing_mode, TextDirection direction)
: writing_mode_(writing_mode), direction_(direction) {}
//
// Inline direction functions.
//
TextDirection Direction() const { return direction_; }
void SetDirection(TextDirection direction) { direction_ = direction; }
bool IsLtr() const { return blink::IsLtr(direction_); }
bool IsRtl() const { return blink::IsRtl(direction_); }
//
// Block direction functions.
//
WritingMode GetWritingMode() const { return writing_mode_; }
void SetWritingMode(WritingMode writing_mode) {
writing_mode_ = writing_mode;
}
bool IsHorizontal() const { return IsHorizontalWritingMode(writing_mode_); }
// Block progression increases in the opposite direction to normal; modes
// vertical-rl.
bool IsFlippedBlocks() const {
return IsFlippedBlocksWritingMode(writing_mode_);
}
// Bottom of the line occurs earlier in the block; modes vertical-lr.
bool IsFlippedLines() const {
return IsFlippedLinesWritingMode(writing_mode_);
}
//
// Functions for both inline and block directions.
//
bool IsHorizontalLtr() const { return IsHorizontal() && IsLtr(); }
bool operator==(const WritingDirectionMode& other) const {
return writing_mode_ == other.writing_mode_ &&
direction_ == other.direction_;
}
bool operator!=(const WritingDirectionMode& other) const {
return !operator==(other);
}
private:
WritingMode writing_mode_;
TextDirection direction_;
};
PLATFORM_EXPORT std::ostream& operator<<(std::ostream&,
const WritingDirectionMode&);
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_PLATFORM_TEXT_WRITING_DIRECTION_MODE_H_
|