summaryrefslogtreecommitdiffstats
path: root/Source/WebCore/rendering/RenderRubyText.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebCore/rendering/RenderRubyText.cpp')
-rw-r--r--Source/WebCore/rendering/RenderRubyText.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/Source/WebCore/rendering/RenderRubyText.cpp b/Source/WebCore/rendering/RenderRubyText.cpp
index 14cf7fc..2b0a360 100644
--- a/Source/WebCore/rendering/RenderRubyText.cpp
+++ b/Source/WebCore/rendering/RenderRubyText.cpp
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2009 Google Inc. All rights reserved.
+ * Copyright (C) 2011 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
@@ -32,6 +33,8 @@
#include "RenderRubyText.h"
+using namespace std;
+
namespace WebCore {
RenderRubyText::RenderRubyText(Node* node)
@@ -48,4 +51,34 @@ bool RenderRubyText::isChildAllowed(RenderObject* child, RenderStyle*) const
return child->isInline();
}
+ETextAlign RenderRubyText::textAlignmentForLine(bool endsWithSoftBreak) const
+{
+ ETextAlign textAlign = style()->textAlign();
+ if (textAlign != TAAUTO)
+ return RenderBlock::textAlignmentForLine(endsWithSoftBreak);
+
+ // The default behavior is to allow ruby text to expand if it is shorter than the ruby base.
+ return JUSTIFY;
+}
+
+void RenderRubyText::adjustInlineDirectionLineBounds(int expansionOpportunityCount, float& logicalLeft, float& logicalWidth) const
+{
+ ETextAlign textAlign = style()->textAlign();
+ if (textAlign != TAAUTO)
+ return RenderBlock::adjustInlineDirectionLineBounds(expansionOpportunityCount, logicalLeft, logicalWidth);
+
+ int maxPreferredLogicalWidth = this->maxPreferredLogicalWidth();
+ if (maxPreferredLogicalWidth >= logicalWidth)
+ return;
+
+ // Inset the ruby text by half the inter-ideograph expansion amount, but no more than a full-width
+ // ruby character on each side.
+ float inset = (logicalWidth - maxPreferredLogicalWidth) / (expansionOpportunityCount + 1);
+ if (expansionOpportunityCount)
+ inset = min<float>(2 * style()->fontSize(), inset);
+
+ logicalLeft += inset / 2;
+ logicalWidth -= inset;
+}
+
} // namespace WebCore