Changeset 51386 in webkit


Ignore:
Timestamp:
Nov 25, 2009 8:50:38 AM (14 years ago)
Author:
benm@google.com
Message:

The select elements do not reflect the actual choice the user makes.
https://bugs.webkit.org/show_bug.cgi?id=31831

Patch by Andrei Popescu <andreip@google.com> on 2009-11-25
Reviewed by Dimitri Glazkov.

Handle the drawing of the listboxes in Android code.

No new features, just fixing an Android problem. Existing layout tests are sufficient.

  • platform/android/RenderThemeAndroid.cpp:

(WebCore::theme):
(WebCore::RenderThemeAndroid::platformActiveSelectionBackgroundColor):
(WebCore::RenderThemeAndroid::platformActiveListBoxSelectionBackgroundColor):
(WebCore::RenderThemeAndroid::platformInactiveListBoxSelectionBackgroundColor):
(WebCore::RenderThemeAndroid::platformActiveListBoxSelectionForegroundColor):
(WebCore::RenderThemeAndroid::platformInactiveListBoxSelectionForegroundColor):
(WebCore::RenderThemeAndroid::adjustButtonStyle):
(WebCore::RenderThemeAndroid::paintTextArea):
(WebCore::RenderThemeAndroid::adjustListboxStyle):

  • platform/android/RenderThemeAndroid.h:
Location:
trunk/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r51385 r51386  
     12009-11-25  Andrei Popescu  <andreip@google.com>
     2
     3        Reviewed by Dimitri Glazkov.
     4
     5        The select elements do not reflect the actual choice the user makes.
     6        https://bugs.webkit.org/show_bug.cgi?id=31831
     7
     8        Handle the drawing of the listboxes in Android code.
     9
     10        No new features, just fixing an Android problem. Existing layout tests are sufficient.
     11
     12        * platform/android/RenderThemeAndroid.cpp:
     13        (WebCore::theme):
     14        (WebCore::RenderThemeAndroid::platformActiveSelectionBackgroundColor):
     15        (WebCore::RenderThemeAndroid::platformActiveListBoxSelectionBackgroundColor):
     16        (WebCore::RenderThemeAndroid::platformInactiveListBoxSelectionBackgroundColor):
     17        (WebCore::RenderThemeAndroid::platformActiveListBoxSelectionForegroundColor):
     18        (WebCore::RenderThemeAndroid::platformInactiveListBoxSelectionForegroundColor):
     19        (WebCore::RenderThemeAndroid::adjustButtonStyle):
     20        (WebCore::RenderThemeAndroid::paintTextArea):
     21        (WebCore::RenderThemeAndroid::adjustListboxStyle):
     22        * platform/android/RenderThemeAndroid.h:
     23
    1242009-11-25  Alexander Pavlov  <apavlov@chromium.org>
    225
  • trunk/WebCore/platform/android/RenderThemeAndroid.cpp

    r50971 r51386  
    11/*
    2  * Copyright 2006, The Android Open Source Project
     2 * Copyright 2009, The Android Open Source Project
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    1414 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    1515 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
    16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
     16 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
    1717 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
    1818 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     
    3030#include "Element.h"
    3131#include "GraphicsContext.h"
     32#include "HTMLNames.h"
     33#include "HTMLOptionElement.h"
     34#include "HTMLSelectElement.h"
     35#include "Node.h"
    3236#include "PlatformGraphicsContext.h"
    3337#include "RenderSkinAndroid.h"
     
    4246// of buttons, so that our button images are large enough to properly fit
    4347// the text.
    44 const int BUTTON_PADDING = 18;
     48const int buttonPadding = 18;
    4549
    4650// Add padding to the fontSize of ListBoxes to get their maximum sizes.
    4751// Listboxes often have a specified size.  Since we change them into
    4852// dropdowns, we want a much smaller height, which encompasses the text.
    49 const int LISTBOX_PADDING = 5;
     53const int listboxPadding = 5;
    5054
    5155// This is the color of selection in a textfield.  It was obtained by checking
    5256// the color of selection in TextViews in the system.
    53 const RGBA32 SELECTION_COLOR = makeRGB(255, 146, 0);
     57const RGBA32 selectionColor = makeRGB(255, 146, 0);
    5458
    5559static SkCanvas* getCanvasFromInfo(const RenderObject::PaintInfo& info)
     
    6064RenderTheme* theme()
    6165{
    62     static RenderThemeAndroid androidTheme;
     66    DEFINE_STATIC_LOCAL(RenderThemeAndroid, androidTheme, ());
    6367    return &androidTheme;
    6468}
     
    98102Color RenderThemeAndroid::platformActiveSelectionBackgroundColor() const
    99103{
    100     return Color(SELECTION_COLOR);
     104    return Color(selectionColor);
    101105}
    102106
     
    117121
    118122Color RenderThemeAndroid::platformTextSearchHighlightColor() const
     123{
     124    return Color(Color::transparent);
     125}
     126
     127Color RenderThemeAndroid::platformActiveListBoxSelectionBackgroundColor() const
     128{
     129    return Color(Color::transparent);
     130}
     131
     132Color RenderThemeAndroid::platformInactiveListBoxSelectionBackgroundColor() const
     133{
     134    return Color(Color::transparent);
     135}
     136
     137Color RenderThemeAndroid::platformActiveListBoxSelectionForegroundColor() const
     138{
     139    return Color(Color::transparent);
     140}
     141
     142Color RenderThemeAndroid::platformInactiveListBoxSelectionForegroundColor() const
    119143{
    120144    return Color(Color::transparent);
     
    178202    style->setPaddingLeft(Length(padding, Fixed));
    179203    style->setPaddingRight(Length(padding, Fixed));
    180     style->setMinHeight(Length(style->fontSize() + BUTTON_PADDING, Fixed));
     204    style->setMinHeight(Length(style->fontSize() + buttonPadding, Fixed));
    181205}
    182206
     
    237261bool RenderThemeAndroid::paintTextArea(RenderObject* obj, const RenderObject::PaintInfo& info, const IntRect& rect)
    238262{
    239     if (obj->isMenuList())
    240         return paintCombo(obj, info, rect);
     263    if (!obj->isListBox())
     264        return true;
     265
     266    paintCombo(obj, info, rect);
     267    RenderStyle* style = obj->style();
     268    if (style)
     269        style->setColor(Color::transparent);
     270    Node* node = obj->node();
     271    if (!node || !node->hasTagName(HTMLNames::selectTag))
     272        return true;
     273
     274    HTMLSelectElement* select = static_cast<HTMLSelectElement*>(node);
     275    // The first item may be visible.  Make sure it does not draw.
     276    // If it has a style, it overrides the RenderListBox's style, so we
     277    // need to make sure both are set to transparent.
     278    node = select->item(0);
     279    if (node) {
     280        RenderObject* renderer = node->renderer();
     281        if (renderer) {
     282            RenderStyle* renderStyle = renderer->style();
     283            if (renderStyle)
     284                renderStyle->setColor(Color::transparent);
     285        }
     286    }
     287    // Find the first selected option, and draw its text.
     288    // FIXME: In a later change, if there is more than one item selected,
     289    // draw a string that says "X items" like iPhone Safari does
     290    int index = select->selectedIndex();
     291    node = select->item(index);
     292    if (!node || !node->hasTagName(HTMLNames::optionTag))
     293        return true;
     294
     295    HTMLOptionElement* option = static_cast<HTMLOptionElement*>(node);
     296    String label = option->textIndentedToRespectGroupLabel();
     297    SkRect r(rect);
     298
     299    SkPaint paint;
     300    paint.setAntiAlias(true);
     301    paint.setTextEncoding(SkPaint::kUTF16_TextEncoding);
     302    // Values for text size and positioning determined by trial and error
     303    paint.setTextSize(r.height() - SkIntToScalar(6));
     304
     305    SkCanvas* canvas = getCanvasFromInfo(info);
     306    int saveCount = canvas->save();
     307    r.fRight -= SkIntToScalar(RenderSkinCombo::extraWidth());
     308    canvas->clipRect(r);
     309    canvas->drawText(label.characters(), label.length() << 1,
     310             r.fLeft + SkIntToScalar(5), r.fBottom - SkIntToScalar(5), paint);
     311    canvas->restoreToCount(saveCount);
     312
    241313    return true;   
    242314}
     
    255327{
    256328    style->setPaddingRight(Length(RenderSkinCombo::extraWidth(), Fixed));
    257     style->setMaxHeight(Length(style->fontSize() + LISTBOX_PADDING, Fixed));
     329    style->setMaxHeight(Length(style->fontSize() + listboxPadding, Fixed));
     330    // Make webkit draw invisible, since it will simply draw the first element
     331    style->setColor(Color::transparent);
    258332    addIntrinsicMargins(style);
    259333}
  • trunk/WebCore/platform/android/RenderThemeAndroid.h

    r50971 r51386  
    6464    virtual Color platformInactiveSelectionForegroundColor() const;
    6565    virtual Color platformTextSearchHighlightColor() const;
    66    
     66
     67    virtual Color platformActiveListBoxSelectionBackgroundColor() const;
     68    virtual Color platformInactiveListBoxSelectionBackgroundColor() const;
     69    virtual Color platformActiveListBoxSelectionForegroundColor() const;
     70    virtual Color platformInactiveListBoxSelectionForegroundColor() const;
     71
    6772    virtual void systemFont(int, WebCore::FontDescription&) const {}
    6873
Note: See TracChangeset for help on using the changeset viewer.