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 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
|
// Copyright 2020 The Chromium Authors
// 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/geometry/logical_direction.h"
#include "third_party/blink/renderer/platform/geometry/physical_direction.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_);
}
bool IsFlippedInlines() const {
return IsRtl() ^ (writing_mode_ == WritingMode::kSidewaysLr);
}
// Bottom of the line occurs earlier in the block; modes vertical-lr.
bool IsFlippedLines() const {
return IsFlippedLinesWritingMode(writing_mode_);
}
// Returns whether x/y is flipped.
bool IsFlippedX() const;
bool IsFlippedY() const;
//
// Functions for both inline and block directions.
//
bool IsHorizontalLtr() const { return IsHorizontal() && IsLtr(); }
// Returns a physical direction corresponding to a logical direction.
PhysicalDirection InlineStart() const;
PhysicalDirection InlineEnd() const;
PhysicalDirection BlockStart() const;
PhysicalDirection BlockEnd() const;
PhysicalDirection LineOver() const;
PhysicalDirection LineUnder() const;
// Returns a logical direction corresponding to a physical direction.
LogicalDirection Top() const;
LogicalDirection Right() const;
LogicalDirection Left() const;
LogicalDirection Bottom() const;
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_;
};
inline bool WritingDirectionMode::IsFlippedX() const {
if (IsHorizontal())
return IsRtl();
return IsFlippedBlocks();
}
inline bool WritingDirectionMode::IsFlippedY() const {
if (IsHorizontal()) {
DCHECK(!IsFlippedBlocks());
return false;
}
return IsFlippedInlines();
}
PLATFORM_EXPORT std::ostream& operator<<(std::ostream&,
const WritingDirectionMode&);
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_PLATFORM_TEXT_WRITING_DIRECTION_MODE_H_
|