Bug 22333 - Text wrapping algorithm for small screens (eg. Mobile screens)
Summary: Text wrapping algorithm for small screens (eg. Mobile screens)
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: Layout and Rendering (show other bugs)
Version: 528+ (Nightly build)
Hardware: S60 Hardware Linux
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-11-18 05:48 PST by Biment Srivastav
Modified: 2010-06-10 16:18 PDT (History)
3 users (show)

See Also:


Attachments
Text Wrapping algorithm (4.84 KB, patch)
2008-11-18 05:50 PST, Biment Srivastav
hausmann: review-
Details | Formatted Diff | Diff
Text wrapping algorithm for fixed width (108.87 KB, application/octet-stream)
2008-11-19 06:02 PST, Biment Srivastav
no flags Details
Text wrapping algorithm for fixed width (108.87 KB, application/octet-stream)
2008-11-19 06:02 PST, Biment Srivastav
no flags Details
screen shot: normal wrapping (53.04 KB, image/jpeg)
2008-11-19 10:26 PST, Mahesh Kulkarni
no flags Details
screen shot: resulted wrapping (50.24 KB, image/jpeg)
2008-11-19 10:27 PST, Mahesh Kulkarni
no flags Details
Patch for review (2.74 KB, patch)
2008-11-19 10:31 PST, Mahesh Kulkarni
koivisto: review-
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Biment Srivastav 2008-11-18 05:48:40 PST
I am attaching patch to avoid too much of horizontal scrolling in small devices, we can improve the algorithm for text wrapping. I have added a new entry in WebCore::Settings to make usage of this algorithm configurable.
Comment 1 Biment Srivastav 2008-11-18 05:50:55 PST
Created attachment 25233 [details]
Text Wrapping algorithm
Comment 2 Simon Hausmann 2008-11-18 07:26:19 PST
Comment on attachment 25233 [details]
Text Wrapping algorithm


> +        void setTextWrappingEnabled(bool);
> +        bool textWrappingEnabled() const { return m_textWrappingEnabled; }

Can you elaborate a bit what exactly this feature/setting implements?

I have doubts about the term "TextWrapping" as WebKit certainly wraps text by default. I think this needs a more specific name.

> @@ -1579,6 +1581,54 @@
>      if (resolver.position().atEnd())
>          return resolver.position();
>  
> +    int frame_width;
> +    RenderView* v = view();
> +    Settings *settings = NULL;
> +    if(v && v->frameView()){
> +       frame_width = v->frameView()->visibleWidth();
> +       frame_width = max(frame_width - leftOffset(m_height), 0);
> +       settings = v->frameView()->frame()->page()->settings(); 
> +    }
> +    if((frame_width < width) && settings && settings->textWrappingEnabled()){
> +       // try to figure out if we want to use text width limit  
> +       bool fixedParent = false;
> +       RenderObject* p = this;
> +       // if we have a fixed height parent box, dont use it  
> +       for (int n=4;p && n>0;n--){
> +            if (p->style()->height().isFixed()) {
> +                fixedParent = true;
> +                break;
> +            }
> +            p = p->parent();
> +       }
> +       // check if there is enough text  
> +       if (!fixedParent) {
> +           RenderObject *o = resolver.position().obj;
> +           unsigned charsFound = 0;
> +           unsigned mostCharsInElement = 0;
> +           while (o) {
> +                 if (o->isText()) {
> +                     RenderText *t = static_cast<RenderText *>(o);
> +                     mostCharsInElement = max(mostCharsInElement, t->textLength());
> +                     charsFound += t->textLength();
> +                     if (charsFound>100 && mostCharsInElement>20) break;
> +                 }
> +                 if (o->isWidget()) {
> +                     charsFound = 0;
> +                     break;
> +                 }
> +             o = bidiNext( resolver.position().block, o);
> +           }
> +          // need at least x amount of characters in the block  
> +          // also if longest single text node (not broken by inlines) is very short  
> +          // it is likely some menu thing and we don't apply the limit  
> +          if (charsFound > 30 && mostCharsInElement > 25)
> +              width = frame_width;
> +
> +       }
> +    }

This code has some coding style issues. There are for example spaces missing between the semicolons separating the arguments to the for() statement, misplaced '*' signs for pointers or the use of NULL instead of 0 for declare a null pointer.
Comment 3 Mark Rowe (bdash) 2008-11-18 10:29:44 PST
It doesn't seem like this is the sort of thing that an application would want to switch at runtime.  That suggests it may be better as a compile-time option similar to USE(LOW_BANDWIDTH_DISPLAY).
Comment 4 Biment Srivastav 2008-11-19 06:02:49 PST
Created attachment 25264 [details]
Text wrapping algorithm for fixed width

I am attaching a patch with compile-time flag.

Brief description about Text wrapping for fixed width: -
To avoid horizontal scrolling while reading text content in small display, we override the fixed width with screen width for the the block which contains text.

I have also attached screen-shots which illusrates the usage of the feature.

normalTextWrappinh.jpg - result without algorithm
resultWithAlgorithm.jpg - result with algorithm
Comment 5 Biment Srivastav 2008-11-19 06:02:51 PST
Created attachment 25265 [details]
Text wrapping algorithm for fixed width

I am attaching a patch with compile-time flag.

Brief description about Text wrapping for fixed width: -
To avoid horizontal scrolling while reading text content in small display, we override the fixed width with screen width for the the block which contains text.

I have also attached screen-shots which illusrates the usage of the feature.

normalTextWrappinh.jpg - result without algorithm
resultWithAlgorithm.jpg - result with algorithm
Comment 6 Mahesh Kulkarni 2008-11-19 10:26:02 PST
Created attachment 25278 [details]
screen shot: normal wrapping
Comment 7 Mahesh Kulkarni 2008-11-19 10:27:35 PST
Created attachment 25279 [details]
screen shot: resulted wrapping
Comment 8 Mahesh Kulkarni 2008-11-19 10:31:16 PST
Created attachment 25280 [details]
Patch for review

changes are in bidi.cpp findNextLineBreak. Algorithm wraps text even in case of fixed width for LOW_BANDWIDTH_DISPLAY.
Comment 9 Darin Adler 2008-11-19 10:38:45 PST
(In reply to comment #8)
> changes are in bidi.cpp findNextLineBreak. Algorithm wraps text even in case of
> fixed width for LOW_BANDWIDTH_DISPLAY.

LOW_BANDWIDTH_DISPLAY seems like a separate switch. I don't think these two should be tied together.
Comment 10 Antti Koivisto 2008-11-19 15:23:09 PST
Comment on attachment 25280 [details]
Patch for review

I wrote the original version of this code many years ago so I probably should not be one to review it. Anyway

- I know what it does and why and how but it is probably not obvious to others. You should include more comments to the code as well as to the change log explaining it better.
- As Darin said, this has nothing to do with LOW_BANDWIDTH_DISPLAY so it should not be behind that feature flag
- Coding style has many errors http://webkit.org/coding/coding-style.html
- It uses magic constants: 100, 30, 25. These should be at least be replaced with named constants.
- frameWidth may be used uninitialized
- How did you test it? Are you sure this code works as expected with the current bidi.cpp? The surrounding code has seen many changes yet this looks very similar it used be.

All in all I'm not sure this code should checked in. It is pretty evil and I'm not sure if anyone else is going to want to use it. It will break easily since there are no buildbots building it. It might be better to apply this sort of changes internally in organizations that want them. I don't see many benefits to anyone in having it in public tree.