Bug 143399

Summary: Code clean up for extracting information from the mix of WritingMode and TextDirection
Product: WebKit Reporter: Said Abou-Hallawa <sabouhallawa>
Component: CSSAssignee: Said Abou-Hallawa <sabouhallawa>
Status: RESOLVED FIXED    
Severity: Normal CC: commit-queue, darin, hyatt, simon.fraser, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch none

Said Abou-Hallawa
Reported 2015-04-03 21:35:15 PDT
There should be eight TextFlows. A TextFlow consists of two directions. The first one controls the line growing direction and the second one controls the block growing direction. The possible TextFlows are: TextFlowEastSouth TextFlowWestSouth TextFlowEastNorth TextFlowWestNorth TextFlowSouthEast TextFlowSouthWest TextFlowNorthEast TextFlowNorthWest We need to extract the following information easily from the TextFlow -- isTextFlowReversed() // RTL -- isTextFlowFlipped() // the opposite direction to normal -- isTextFlowVertical() // The line grows vertically I came across the function resolveToPhysicalProperty() and I found out it is needlessly complicated and hard to read. I think mixing the WritingMode and the TextDirection into TextFlow and choosing their values carefully to ease implementing the above functions can make things clearer.
Attachments
Patch (11.41 KB, patch)
2015-04-03 21:56 PDT, Said Abou-Hallawa
no flags
Patch (36.04 KB, patch)
2015-05-11 17:04 PDT, Said Abou-Hallawa
no flags
Patch (36.61 KB, patch)
2015-05-11 17:32 PDT, Said Abou-Hallawa
no flags
Patch (37.95 KB, patch)
2015-05-11 17:38 PDT, Said Abou-Hallawa
no flags
Patch (39.58 KB, patch)
2015-05-11 20:14 PDT, Said Abou-Hallawa
no flags
Patch (39.63 KB, patch)
2015-05-11 20:38 PDT, Said Abou-Hallawa
no flags
Patch (39.63 KB, patch)
2015-05-11 20:55 PDT, Said Abou-Hallawa
no flags
Patch (39.73 KB, patch)
2015-05-11 21:12 PDT, Said Abou-Hallawa
no flags
Patch (39.71 KB, patch)
2015-05-11 21:53 PDT, Said Abou-Hallawa
no flags
Patch (39.71 KB, patch)
2015-05-12 09:15 PDT, Said Abou-Hallawa
no flags
Patch (39.74 KB, patch)
2015-05-12 09:51 PDT, Said Abou-Hallawa
no flags
Patch (24.86 KB, patch)
2015-05-28 12:27 PDT, Said Abou-Hallawa
no flags
Patch (25.94 KB, patch)
2015-05-28 13:19 PDT, Said Abou-Hallawa
no flags
Said Abou-Hallawa
Comment 1 2015-04-03 21:56:44 PDT
WebKit Commit Bot
Comment 2 2015-04-03 21:58:11 PDT
Attachment 250122 [details] did not pass style-queue: ERROR: Source/WebCore/platform/text/TextFlags.h:31: enum members should use InterCaps with an initial capital letter. [readability/enum_casing] [4] ERROR: Source/WebCore/platform/text/WritingMode.h:41: One space before end of line comments [whitespace/comments] [5] Total errors found: 2 in 4 files If any of these errors are false positives, please file a bug against check-webkit-style.
Said Abou-Hallawa
Comment 3 2015-05-11 17:04:29 PDT
WebKit Commit Bot
Comment 4 2015-05-11 17:06:02 PDT
Attachment 252909 [details] did not pass style-queue: ERROR: Source/WebCore/platform/text/TextFlags.h:31: enum members should use InterCaps with an initial capital letter. [readability/enum_casing] [4] Total errors found: 1 in 8 files If any of these errors are false positives, please file a bug against check-webkit-style.
Darin Adler
Comment 5 2015-05-11 17:30:29 PDT
Comment on attachment 252909 [details] Patch Need to remove LengthBox.cpp from more build files. Just do a grep to see where it’s mentioned.
Said Abou-Hallawa
Comment 6 2015-05-11 17:32:47 PDT
WebKit Commit Bot
Comment 7 2015-05-11 17:34:21 PDT
Attachment 252913 [details] did not pass style-queue: ERROR: Source/WebCore/platform/text/TextFlags.h:31: enum members should use InterCaps with an initial capital letter. [readability/enum_casing] [4] Total errors found: 1 in 8 files If any of these errors are false positives, please file a bug against check-webkit-style.
Said Abou-Hallawa
Comment 8 2015-05-11 17:38:31 PDT
WebKit Commit Bot
Comment 9 2015-05-11 17:41:38 PDT
Attachment 252914 [details] did not pass style-queue: ERROR: Source/WebCore/platform/text/TextFlags.h:31: enum members should use InterCaps with an initial capital letter. [readability/enum_casing] [4] Total errors found: 1 in 8 files If any of these errors are false positives, please file a bug against check-webkit-style.
Darin Adler
Comment 10 2015-05-11 18:22:55 PDT
Comment on attachment 252914 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=252914&action=review > Source/WebCore/platform/LengthBox.h:37 > + : m_sides { type, type, type, type } C:\cygwin\home\buildbot\WebKit\Source\WebCore\platform\LengthBox.h(38): error C2536: 'WebCore::LengthBox::WebCore::LengthBox::m_sides' : cannot specify explicit initializer for arrays (C:\cygwin\home\buildbot\WebKit\WebKitBuild\Release\obj32\WebCore\DerivedSources\StyleBuilder.cpp) [C:\cygwin\home\buildbot\WebKit\Source\WebCore\WebCore.vcxproj\WebCore.vcxproj] C:\cygwin\home\buildbot\WebKit\Source\WebCore\platform\LengthBox.h(87) : see declaration of 'WebCore::LengthBox::m_sides' Windows compiler doesn’t like this. Maybe std::array will help. > Source/WebCore/platform/LengthBox.h:87 > + Length m_sides[4]; If we used std::array here instead, then operator== above would not have to list all four sides. It could just say return m_sides == other.m_sides instead. > Source/WebCore/platform/text/TextFlags.h:31 > +enum TextDirection { LTR, RTL }; Logical change. But seems slightly dangerous to change this unless we audit every single call site that uses TextDirection. Some of them might be doing if (x). > Source/WebCore/platform/text/WritingMode.h:44 > +#define MAKE_TEXT_FLOW(writingMode, direction) ((writingMode) << 1 | (direction)) Seems like we could use a constexpr function some day, maybe only in the future. I suggest also #undef MAKE_TEXT_FLOW after we are done with it.
Said Abou-Hallawa
Comment 11 2015-05-11 20:14:12 PDT
WebKit Commit Bot
Comment 12 2015-05-11 20:15:45 PDT
Attachment 252924 [details] did not pass style-queue: ERROR: Source/WebCore/platform/text/TextFlags.h:31: enum members should use InterCaps with an initial capital letter. [readability/enum_casing] [4] Total errors found: 1 in 8 files If any of these errors are false positives, please file a bug against check-webkit-style.
Said Abou-Hallawa
Comment 13 2015-05-11 20:38:18 PDT
WebKit Commit Bot
Comment 14 2015-05-11 20:39:55 PDT
Attachment 252926 [details] did not pass style-queue: ERROR: Source/WebCore/platform/text/TextFlags.h:31: enum members should use InterCaps with an initial capital letter. [readability/enum_casing] [4] Total errors found: 1 in 8 files If any of these errors are false positives, please file a bug against check-webkit-style.
Said Abou-Hallawa
Comment 15 2015-05-11 20:55:47 PDT
WebKit Commit Bot
Comment 16 2015-05-11 20:57:15 PDT
Attachment 252927 [details] did not pass style-queue: ERROR: Source/WebCore/platform/text/TextFlags.h:31: enum members should use InterCaps with an initial capital letter. [readability/enum_casing] [4] Total errors found: 1 in 8 files If any of these errors are false positives, please file a bug against check-webkit-style.
Said Abou-Hallawa
Comment 17 2015-05-11 21:12:20 PDT
WebKit Commit Bot
Comment 18 2015-05-11 21:18:50 PDT
Attachment 252930 [details] did not pass style-queue: ERROR: Source/WebCore/platform/text/TextFlags.h:31: enum members should use InterCaps with an initial capital letter. [readability/enum_casing] [4] Total errors found: 1 in 8 files If any of these errors are false positives, please file a bug against check-webkit-style.
Said Abou-Hallawa
Comment 19 2015-05-11 21:53:19 PDT
WebKit Commit Bot
Comment 20 2015-05-11 21:56:19 PDT
Attachment 252933 [details] did not pass style-queue: ERROR: Source/WebCore/platform/text/TextFlags.h:31: enum members should use InterCaps with an initial capital letter. [readability/enum_casing] [4] Total errors found: 1 in 8 files If any of these errors are false positives, please file a bug against check-webkit-style.
Said Abou-Hallawa
Comment 21 2015-05-12 09:15:36 PDT
WebKit Commit Bot
Comment 22 2015-05-12 09:17:31 PDT
Attachment 252966 [details] did not pass style-queue: ERROR: Source/WebCore/platform/text/TextFlags.h:31: enum members should use InterCaps with an initial capital letter. [readability/enum_casing] [4] Total errors found: 1 in 8 files If any of these errors are false positives, please file a bug against check-webkit-style.
Said Abou-Hallawa
Comment 23 2015-05-12 09:51:23 PDT
WebKit Commit Bot
Comment 24 2015-05-12 09:53:23 PDT
Attachment 252967 [details] did not pass style-queue: ERROR: Source/WebCore/platform/text/TextFlags.h:31: enum members should use InterCaps with an initial capital letter. [readability/enum_casing] [4] Total errors found: 1 in 8 files If any of these errors are false positives, please file a bug against check-webkit-style.
Simon Fraser (smfr)
Comment 25 2015-05-12 10:52:39 PDT
Comment on attachment 252967 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=252967&action=review > Source/WebCore/platform/text/WritingMode.h:49 > +enum TextFlow { > + TextFlowEastSouth = MAKE_TEXT_FLOW(TopToBottomWritingMode, LTR), enum class would avoid the repetition here: enum class TextFlow { EastSouth, .... But I would prefer something like BlockEastInlineSouth (if that's accurate).
Dave Hyatt
Comment 26 2015-05-12 10:57:01 PDT
Comment on attachment 252967 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=252967&action=review > Source/WebCore/platform/text/WritingMode.h:56 > + TextFlowWestSouth = MAKE_TEXT_FLOW(TopToBottomWritingMode, RTL), > + TextFlowEastNorth = MAKE_TEXT_FLOW(BottomToTopWritingMode, LTR), > + TextFlowWestNorth = MAKE_TEXT_FLOW(BottomToTopWritingMode, RTL), > + TextFlowSouthEast = MAKE_TEXT_FLOW(LeftToRightWritingMode, LTR), > + TextFlowSouthWest = MAKE_TEXT_FLOW(LeftToRightWritingMode, RTL), > + TextFlowNorthEast = MAKE_TEXT_FLOW(RightToLeftWritingMode, LTR), > + TextFlowNorthWest = MAKE_TEXT_FLOW(RightToLeftWritingMode, RTL) I think using cardinal directions is weird. In my opinion, a better convention would be to just use the terminology from Internet Explorer's original writing mode definitions, e.g., tb-rl tb-lr etc.
Said Abou-Hallawa
Comment 27 2015-05-12 14:27:52 PDT
(In reply to comment #26) > Comment on attachment 252967 [details] > Patch > > View in context: > https://bugs.webkit.org/attachment.cgi?id=252967&action=review > > > Source/WebCore/platform/text/WritingMode.h:56 > > + TextFlowWestSouth = MAKE_TEXT_FLOW(TopToBottomWritingMode, RTL), > > + TextFlowEastNorth = MAKE_TEXT_FLOW(BottomToTopWritingMode, LTR), > > + TextFlowWestNorth = MAKE_TEXT_FLOW(BottomToTopWritingMode, RTL), > > + TextFlowSouthEast = MAKE_TEXT_FLOW(LeftToRightWritingMode, LTR), > > + TextFlowSouthWest = MAKE_TEXT_FLOW(LeftToRightWritingMode, RTL), > > + TextFlowNorthEast = MAKE_TEXT_FLOW(RightToLeftWritingMode, LTR), > > + TextFlowNorthWest = MAKE_TEXT_FLOW(RightToLeftWritingMode, RTL) > > I think using cardinal directions is weird. In my opinion, a better > convention would be to just use the terminology from Internet Explorer's > original writing mode definitions, e.g., > > tb-rl > tb-lr > > etc. The problem with this naming is the writing_mode is physical direction but the text_direction is logical direction relative to the writing mode. For example Internet Explorer's naming in these cases lr-lr == TextFlowSouthEast lr-rl == TextFlowSouthWest rl-lr == TextFlowNorthEast rl-rl == TextFlowNorthWest do not indicate easily where the text grows. But cardinal directions give you that easily. The first one TextFlowSouthEast says: 1. The line grows from South-to-North 2. The paragraph grows from East-to-West But with "lr-lr": 1. The first "lr" says the paragraph grows from East-to-West 2. For the second "lr", I have to remember that the text is vertical so the left now means the bottom so I know that the line grows from South-to-North.
Said Abou-Hallawa
Comment 28 2015-05-28 12:27:11 PDT
WebKit Commit Bot
Comment 29 2015-05-28 12:30:31 PDT
Attachment 253855 [details] did not pass style-queue: ERROR: Source/WebCore/platform/text/WritingMode.h:37: enum members should use InterCaps with an initial capital letter. [readability/enum_casing] [4] Total errors found: 1 in 15 files If any of these errors are false positives, please file a bug against check-webkit-style.
Said Abou-Hallawa
Comment 30 2015-05-28 13:19:30 PDT
WebKit Commit Bot
Comment 31 2015-05-28 13:21:06 PDT
Attachment 253857 [details] did not pass style-queue: ERROR: Source/WebCore/platform/text/WritingMode.h:37: enum members should use InterCaps with an initial capital letter. [readability/enum_casing] [4] Total errors found: 1 in 16 files If any of these errors are false positives, please file a bug against check-webkit-style.
Said Abou-Hallawa
Comment 32 2015-05-28 14:08:36 PDT
(In reply to comment #10) > Comment on attachment 252914 [details] > Patch > > View in context: > https://bugs.webkit.org/attachment.cgi?id=252914&action=review > > > Source/WebCore/platform/LengthBox.h:37 > > + : m_sides { type, type, type, type } > > C:\cygwin\home\buildbot\WebKit\Source\WebCore\platform\LengthBox.h(38): > error C2536: 'WebCore::LengthBox::WebCore::LengthBox::m_sides' : cannot > specify explicit initializer for arrays > (C: > \cygwin\home\buildbot\WebKit\WebKitBuild\Release\obj32\WebCore\DerivedSources > \StyleBuilder.cpp) > [C:\cygwin\home\buildbot\WebKit\Source\WebCore\WebCore.vcxproj\WebCore. > vcxproj] > > C:\cygwin\home\buildbot\WebKit\Source\WebCore\platform\LengthBox.h(87) : see > declaration of 'WebCore::LengthBox::m_sides' > > Windows compiler doesn’t like this. Maybe std::array will help. > This has been fixed and submitted in http://trac.webkit.org/changeset/184895. > > Source/WebCore/platform/LengthBox.h:87 > > + Length m_sides[4]; > > If we used std::array here instead, then operator== above would not have to > list all four sides. It could just say return m_sides == other.m_sides > instead. > This has been fixed and submitted in http://trac.webkit.org/changeset/184895. > > Source/WebCore/platform/text/TextFlags.h:31 > > +enum TextDirection { LTR, RTL }; > > Logical change. But seems slightly dangerous to change this unless we audit > every single call site that uses TextDirection. Some of them might be doing > if (x). > I checked all the places which use TextDirection and fortunately I did not find condition like "if (textDirection)" or "if (!textDirection)". So changing the order of LTR and RTL should be safe. > > Source/WebCore/platform/text/WritingMode.h:44 > > +#define MAKE_TEXT_FLOW(writingMode, direction) ((writingMode) << 1 | (direction)) > > Seems like we could use a constexpr function some day, maybe only in the > future. I suggest also #undef MAKE_TEXT_FLOW after we are done with it. I tried using constexpr and its seems to work except on Windows. So I gave up and I left the macro and the function as they are but I added the #undef as suggested.
WebKit Commit Bot
Comment 33 2015-05-28 14:55:51 PDT
Comment on attachment 253857 [details] Patch Clearing flags on attachment: 253857 Committed r184962: <http://trac.webkit.org/changeset/184962>
WebKit Commit Bot
Comment 34 2015-05-28 14:55:57 PDT
All reviewed patches have been landed. Closing bug.
Radar WebKit Bug Importer
Comment 35 2015-05-28 16:15:22 PDT
Note You need to log in before you can comment on or make changes to this bug.