Changeset 54586 in webkit


Ignore:
Timestamp:
Feb 9, 2010 8:48:49 PM (14 years ago)
Author:
eric@webkit.org
Message:

2010-02-09 James Hawkins <jhawkins@chromium.org>

Reviewed by Darin Fisher.

[Chromium] Refactor AutocompletePopupMenuClient into a base class,
SuggestionsPopupMenuClient, and two derived classes,
AutocompletePopupMenuClient and AutoFillPopupMenuClient. Currently
the behavior of suggestions popups has not changed.

https://bugs.webkit.org/show_bug.cgi?id=34721

  • WebKit.gyp:
  • public/WebView.h:
  • src/AutoFillPopupMenuClient.cpp: Added.
  • src/AutoFillPopupMenuClient.h: Added.
  • src/AutocompletePopupMenuClient.cpp: (WebKit::AutocompletePopupMenuClient::getSuggestionsCount): (WebKit::AutocompletePopupMenuClient::getSuggestion): (WebKit::AutocompletePopupMenuClient::removeSuggestionAtIndex): (WebKit::AutocompletePopupMenuClient::initialize): (WebKit::AutocompletePopupMenuClient::setSuggestions):
  • src/AutocompletePopupMenuClient.h:
  • src/SuggestionsPopupMenuClient.cpp: Added.
  • src/SuggestionsPopupMenuClient.h: Added.
  • src/WebViewImpl.cpp: (WebKit::WebViewImpl::WebViewImpl): (WebKit::WebViewImpl::keyEvent): (WebKit::WebViewImpl::autocompleteHandleKeyEvent): (WebKit::WebViewImpl::applyAutofillSuggestions): (WebKit::WebViewImpl::applyAutoFillSuggestions): (WebKit::WebViewImpl::applyAutocompleteSuggestions):
  • src/WebViewImpl.h:
Location:
trunk/WebKit/chromium
Files:
3 added
7 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/WebKit/chromium/ChangeLog

    r54584 r54586  
     12010-02-09  James Hawkins  <jhawkins@chromium.org>
     2
     3        Reviewed by Darin Fisher.
     4
     5        [Chromium] Refactor AutocompletePopupMenuClient into a base class,
     6        SuggestionsPopupMenuClient, and two derived classes,
     7        AutocompletePopupMenuClient and AutoFillPopupMenuClient.  Currently
     8        the behavior of suggestions popups has not changed.
     9
     10        https://bugs.webkit.org/show_bug.cgi?id=34721
     11
     12        * WebKit.gyp:
     13        * public/WebView.h:
     14        * src/AutoFillPopupMenuClient.cpp: Added.
     15        * src/AutoFillPopupMenuClient.h: Added.
     16        * src/AutocompletePopupMenuClient.cpp:
     17        (WebKit::AutocompletePopupMenuClient::getSuggestionsCount):
     18        (WebKit::AutocompletePopupMenuClient::getSuggestion):
     19        (WebKit::AutocompletePopupMenuClient::removeSuggestionAtIndex):
     20        (WebKit::AutocompletePopupMenuClient::initialize):
     21        (WebKit::AutocompletePopupMenuClient::setSuggestions):
     22        * src/AutocompletePopupMenuClient.h:
     23        * src/SuggestionsPopupMenuClient.cpp: Added.
     24        * src/SuggestionsPopupMenuClient.h: Added.
     25        * src/WebViewImpl.cpp:
     26        (WebKit::WebViewImpl::WebViewImpl):
     27        (WebKit::WebViewImpl::keyEvent):
     28        (WebKit::WebViewImpl::autocompleteHandleKeyEvent):
     29        (WebKit::WebViewImpl::applyAutofillSuggestions):
     30        (WebKit::WebViewImpl::applyAutoFillSuggestions):
     31        (WebKit::WebViewImpl::applyAutocompleteSuggestions):
     32        * src/WebViewImpl.h:
     33
    1342010-02-09  Chris Guillory  <ctguil@google.com>
    235
  • trunk/WebKit/chromium/WebKit.gyp

    r54565 r54586  
    201201                'src/AutocompletePopupMenuClient.cpp',
    202202                'src/AutocompletePopupMenuClient.h',
     203                'src/AutoFillPopupMenuClient.cpp',
     204                'src/AutoFillPopupMenuClient.h',
    203205                'src/BackForwardListClientImpl.cpp',
    204206                'src/BackForwardListClientImpl.h',
     
    259261                'src/StorageNamespaceProxy.cpp',
    260262                'src/StorageNamespaceProxy.h',
     263                'src/SuggestionsPopupMenuClient.cpp',
     264                'src/SuggestionsPopupMenuClient.h',
    261265                'src/TemporaryGlue.h',
    262266                'src/ToolsAgent.h',
  • trunk/WebKit/chromium/public/WebView.h

    r54458 r54586  
    224224
    225225
    226     // Autofill ------------------------------------------------------------
    227 
    228     // Notifies the WebView that autofill suggestions are available for a node.
     226    // AutoFill / Autocomplete ---------------------------------------------
     227
     228    // DEPRECATED: WebView::applyAutocompleteSuggestions is the new way to
     229    // access this.
    229230    virtual void applyAutofillSuggestions(
    230231        const WebNode&,
     
    232233        int defaultSuggestionIndex) = 0;
    233234
     235    // Notifies the WebView that AutoFill suggestions are available for a node.
     236    virtual void applyAutoFillSuggestions(
     237        const WebNode&,
     238        const WebVector<WebString>& names,
     239        const WebVector<WebString>& labels,
     240        int defaultSuggestionIndex) = 0;
     241
     242    // Notifies the WebView that Autocomplete suggestions are available for a
     243    // node.
     244    virtual void applyAutocompleteSuggestions(
     245        const WebNode&,
     246        const WebVector<WebString>& suggestions,
     247        int defaultSuggestionIndex) = 0;
     248
    234249    // DEPRECATED: WebView::hideSuggestionsPopup is the new way to access this.
    235250    virtual void hideAutofillPopup() = 0;
  • trunk/WebKit/chromium/src/AutocompletePopupMenuClient.cpp

    r54458 r54586  
    11/*
    2  * Copyright (C) 2009 Google Inc. All rights reserved.
     2 * Copyright (C) 2010 Google Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    3232#include "AutocompletePopupMenuClient.h"
    3333
    34 #include "CSSStyleSelector.h"
    35 #include "CSSValueKeywords.h"
    36 #include "FrameView.h"
    3734#include "HTMLInputElement.h"
    38 #include "RenderTheme.h"
     35#include "WebString.h"
    3936#include "WebVector.h"
    40 #include "WebViewImpl.h"
    4137
    4238using namespace WebCore;
     
    4440namespace WebKit {
    4541
    46 AutocompletePopupMenuClient::AutocompletePopupMenuClient(WebViewImpl* webView)
    47     : m_textField(0)
    48     , m_selectedIndex(0)
    49     , m_webView(webView)
     42unsigned AutocompletePopupMenuClient::getSuggestionsCount() const
    5043{
     44    return m_suggestions.size();
    5145}
    5246
    53 AutocompletePopupMenuClient::~AutocompletePopupMenuClient()
     47WebString AutocompletePopupMenuClient::getSuggestion(unsigned listIndex) const
    5448{
     49    ASSERT(listIndex >= 0 && listIndex < m_suggestions.size());
     50    return m_suggestions[listIndex];
     51}
     52
     53void AutocompletePopupMenuClient::removeSuggestionAtIndex(unsigned listIndex)
     54{
     55    ASSERT(listIndex >= 0 && listIndex < m_suggestions.size());
     56    m_suggestions.remove(listIndex);
    5557}
    5658
     
    6163{
    6264    ASSERT(defaultSuggestionIndex < static_cast<int>(suggestions.size()));
    63     m_textField = textField;
    64     m_selectedIndex = defaultSuggestionIndex;
     65
     66    // The suggestions must be set before initializing the
     67    // SuggestionsPopupMenuClient.
    6568    setSuggestions(suggestions);
    6669
    67     FontDescription fontDescription;
    68     m_webView->theme()->systemFont(CSSValueWebkitControl, fontDescription);
    69     // Use a smaller font size to match IE/Firefox.
    70     // FIXME: http://crbug.com/7376 use the system size instead of a
    71     //        fixed font size value.
    72     fontDescription.setComputedSize(12.0);
    73     Font font(fontDescription, 0, 0);
    74     font.update(textField->document()->styleSelector()->fontSelector());
    75     // The direction of text in popup menu is set the same as the direction of
    76     // the input element: textField.
    77     m_style.set(new PopupMenuStyle(Color::black, Color::white, font, true,
    78                                    Length(WebCore::Fixed),
    79                                    textField->renderer()->style()->direction()));
    80 }
    81 
    82 void AutocompletePopupMenuClient::valueChanged(unsigned listIndex, bool fireEvents)
    83 {
    84     m_textField->setValue(m_suggestions[listIndex]);
    85     EditorClientImpl* editor =
    86         static_cast<EditorClientImpl*>(m_webView->page()->editorClient());
    87     ASSERT(editor);
    88     editor->onAutofillSuggestionAccepted(
    89         static_cast<HTMLInputElement*>(m_textField.get()));
    90 }
    91 
    92 String AutocompletePopupMenuClient::itemText(unsigned listIndex) const
    93 {
    94     return m_suggestions[listIndex];
    95 }
    96 
    97 PopupMenuStyle AutocompletePopupMenuClient::itemStyle(unsigned listIndex) const
    98 {
    99     return *m_style;
    100 }
    101 
    102 PopupMenuStyle AutocompletePopupMenuClient::menuStyle() const
    103 {
    104     return *m_style;
    105 }
    106 
    107 int AutocompletePopupMenuClient::clientPaddingLeft() const
    108 {
    109     // Bug http://crbug.com/7708 seems to indicate the style can be 0.
    110     RenderStyle* style = textFieldStyle();
    111     return style ? m_webView->theme()->popupInternalPaddingLeft(style) : 0;
    112 }
    113 
    114 int AutocompletePopupMenuClient::clientPaddingRight() const
    115 {
    116     // Bug http://crbug.com/7708 seems to indicate the style can be 0.
    117     RenderStyle* style = textFieldStyle();
    118     return style ? m_webView->theme()->popupInternalPaddingRight(style) : 0;
    119 }
    120 
    121 void AutocompletePopupMenuClient::popupDidHide()
    122 {
    123     m_webView->suggestionsPopupDidHide();
    124 }
    125 
    126 void AutocompletePopupMenuClient::setTextFromItem(unsigned listIndex)
    127 {
    128     m_textField->setValue(m_suggestions[listIndex]);
    129 }
    130 
    131 FontSelector* AutocompletePopupMenuClient::fontSelector() const
    132 {
    133     return m_textField->document()->styleSelector()->fontSelector();
    134 }
    135 
    136 HostWindow* AutocompletePopupMenuClient::hostWindow() const
    137 {
    138     return m_textField->document()->view()->hostWindow();
    139 }
    140 
    141 PassRefPtr<Scrollbar> AutocompletePopupMenuClient::createScrollbar(
    142     ScrollbarClient* client,
    143     ScrollbarOrientation orientation,
    144     ScrollbarControlSize size)
    145 {
    146     return Scrollbar::createNativeScrollbar(client, orientation, size);
     70    SuggestionsPopupMenuClient::initialize(textField, defaultSuggestionIndex);
    14771}
    14872
     
    15276    for (size_t i = 0; i < suggestions.size(); ++i)
    15377        m_suggestions.append(suggestions[i]);
     78
    15479    // Try to preserve selection if possible.
    155     if (m_selectedIndex >= static_cast<int>(suggestions.size()))
    156         m_selectedIndex = -1;
    157 }
    158 
    159 void AutocompletePopupMenuClient::removeItemAtIndex(int index)
    160 {
    161     ASSERT(index >= 0 && index < static_cast<int>(m_suggestions.size()));
    162     m_suggestions.remove(index);
    163 }
    164 
    165 RenderStyle* AutocompletePopupMenuClient::textFieldStyle() const
    166 {
    167     RenderStyle* style = m_textField->computedStyle();
    168     if (!style) {
    169         // It seems we can only have a 0 style in a TextField if the
    170         // node is detached, in which case we the popup shoud not be
    171         // showing.  Please report this in http://crbug.com/7708 and
    172         // include the page you were visiting.
    173         ASSERT_NOT_REACHED();
    174     }
    175     return style;
     80    if (getSelectedIndex() >= static_cast<int>(suggestions.size()))
     81        setSelectedIndex(-1);
    17682}
    17783
  • trunk/WebKit/chromium/src/AutocompletePopupMenuClient.h

    r53716 r54586  
    11/*
    2  * Copyright (C) 2009 Google Inc. All rights reserved.
     2 * Copyright (C) 2010 Google Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2929 */
    3030
    31 #include "PopupMenuClient.h"
     31#ifndef AutocompletePopupMenuClient_h
     32#define AutocompletePopupMenuClient_h
     33 
     34#include "SuggestionsPopupMenuClient.h"
    3235
    3336namespace WebCore {
    3437class HTMLInputElement;
    35 class PopupMenuStyle;
    36 class RenderStyle;
    3738}
    3839
    3940namespace WebKit {
    4041class WebString;
    41 class WebViewImpl;
    4242template <typename T> class WebVector;
    4343
    44 // AutocompletePopupMenuClient
    45 class AutocompletePopupMenuClient : public WebCore::PopupMenuClient {
     44// The Autocomplete suggestions popup menu client, used to display a list of
     45// autocomplete suggestions.
     46class AutocompletePopupMenuClient : public SuggestionsPopupMenuClient {
    4647public:
    47     AutocompletePopupMenuClient(WebViewImpl* webview);
    48     ~AutocompletePopupMenuClient();
     48    // SuggestionsPopupMenuClient implementation:
     49    virtual unsigned getSuggestionsCount() const;
     50    virtual WebString getSuggestion(unsigned listIndex) const;
     51    virtual void removeSuggestionAtIndex(unsigned listIndex);
    4952
    5053    void initialize(WebCore::HTMLInputElement*,
     
    5255                    int defaultSuggestionIndex);
    5356
    54     WebCore::HTMLInputElement* textField() const { return m_textField.get(); }
    55 
    5657    void setSuggestions(const WebVector<WebString>&);
    57     void removeItemAtIndex(int index);
    58 
    59     // WebCore::PopupMenuClient methods:
    60     virtual void valueChanged(unsigned listIndex, bool fireEvents = true);
    61     virtual WebCore::String itemText(unsigned listIndex) const;
    62     virtual WebCore::String itemToolTip(unsigned lastIndex) const { return WebCore::String(); }
    63     virtual bool itemIsEnabled(unsigned listIndex) const { return true; }
    64     virtual WebCore::PopupMenuStyle itemStyle(unsigned listIndex) const;
    65     virtual WebCore::PopupMenuStyle menuStyle() const;
    66     virtual int clientInsetLeft() const { return 0; }
    67     virtual int clientInsetRight() const { return 0; }
    68     virtual int clientPaddingLeft() const;
    69     virtual int clientPaddingRight() const;
    70     virtual int listSize() const { return m_suggestions.size(); }
    71     virtual int selectedIndex() const { return m_selectedIndex; }
    72     virtual void popupDidHide();
    73     virtual bool itemIsSeparator(unsigned listIndex) const { return false; }
    74     virtual bool itemIsLabel(unsigned listIndex) const { return false; }
    75     virtual bool itemIsSelected(unsigned listIndex) const { return false; }
    76     virtual bool shouldPopOver() const { return false; }
    77     virtual bool valueShouldChangeOnHotTrack() const { return false; }
    78     virtual void setTextFromItem(unsigned listIndex);
    79     virtual WebCore::FontSelector* fontSelector() const;
    80     virtual WebCore::HostWindow* hostWindow() const;
    81     virtual PassRefPtr<WebCore::Scrollbar> createScrollbar(
    82         WebCore::ScrollbarClient* client,
    83         WebCore::ScrollbarOrientation orientation,
    84         WebCore::ScrollbarControlSize size);
    8558
    8659private:
    87     WebCore::RenderStyle* textFieldStyle() const;
    88 
    89     RefPtr<WebCore::HTMLInputElement> m_textField;
    9060    Vector<WebCore::String> m_suggestions;
    91     int m_selectedIndex;
    92     WebViewImpl* m_webView;
    93     OwnPtr<WebCore::PopupMenuStyle> m_style;
    9461};
    9562
    9663} // namespace WebKit
     64
     65#endif
  • trunk/WebKit/chromium/src/SuggestionsPopupMenuClient.h

    r54585 r54586  
    11/*
    2  * Copyright (C) 2009 Google Inc. All rights reserved.
     2 * Copyright (C) 2010 Google Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    3131#include "PopupMenuClient.h"
    3232
     33#ifndef SuggestionsPopupMenuClient_h
     34#define SuggestionsPopupMenuClient_h
     35
    3336namespace WebCore {
    3437class HTMLInputElement;
     
    4245template <typename T> class WebVector;
    4346
    44 // AutocompletePopupMenuClient
    45 class AutocompletePopupMenuClient : public WebCore::PopupMenuClient {
     47// The Suggestions popup menu client, used to display a list of suggestions.
     48class SuggestionsPopupMenuClient : public WebCore::PopupMenuClient {
    4649public:
    47     AutocompletePopupMenuClient(WebViewImpl* webview);
    48     ~AutocompletePopupMenuClient();
     50    SuggestionsPopupMenuClient();
     51    virtual ~SuggestionsPopupMenuClient();
    4952
    50     void initialize(WebCore::HTMLInputElement*,
    51                     const WebVector<WebString>& suggestions,
    52                     int defaultSuggestionIndex);
     53    // Returns the number of suggestions available.
     54    virtual unsigned getSuggestionsCount() const = 0;
    5355
    54     WebCore::HTMLInputElement* textField() const { return m_textField.get(); }
     56    // Returns the suggestion at |listIndex|.
     57    virtual WebString getSuggestion(unsigned listIndex) const = 0;
    5558
    56     void setSuggestions(const WebVector<WebString>&);
    57     void removeItemAtIndex(int index);
     59    // Removes the suggestion at |listIndex| from the list of suggestions.
     60    virtual void removeSuggestionAtIndex(unsigned listIndex) = 0;
    5861
    5962    // WebCore::PopupMenuClient methods:
    6063    virtual void valueChanged(unsigned listIndex, bool fireEvents = true);
     64    virtual void selectionChanged(unsigned listIndex, bool fireEvents = true);
    6165    virtual WebCore::String itemText(unsigned listIndex) const;
    6266    virtual WebCore::String itemToolTip(unsigned lastIndex) const { return WebCore::String(); }
     
    6872    virtual int clientPaddingLeft() const;
    6973    virtual int clientPaddingRight() const;
    70     virtual int listSize() const { return m_suggestions.size(); }
     74    virtual int listSize() const { return getSuggestionsCount(); }
    7175    virtual int selectedIndex() const { return m_selectedIndex; }
    7276    virtual void popupDidHide();
     
    8488        WebCore::ScrollbarControlSize size);
    8589
     90protected:
     91    void initialize(WebCore::HTMLInputElement* textField,
     92                    int defaultSuggestionIndex);
     93    void setInitialSuggestion();
     94
     95    int getSelectedIndex() const { return m_selectedIndex; }
     96    void setSelectedIndex(int index) { m_selectedIndex = index; }
     97
     98    void setSuggestedValue(const WebString& suggestion);
     99
     100    WebViewImpl* getWebView() const;
     101    WebCore::HTMLInputElement* getTextField() const { return m_textField.get(); }
     102
    86103private:
    87104    WebCore::RenderStyle* textFieldStyle() const;
     105    void resetLastSuggestion();
    88106
    89107    RefPtr<WebCore::HTMLInputElement> m_textField;
    90     Vector<WebCore::String> m_suggestions;
    91108    int m_selectedIndex;
    92     WebViewImpl* m_webView;
     109    WebCore::String m_typedFieldValue;
    93110    OwnPtr<WebCore::PopupMenuStyle> m_style;
     111    typedef HashMap<WebCore::String, WebCore::String> FieldValuesMap;
     112    OwnPtr<FieldValuesMap> m_lastFieldValues;
    94113};
    95114
    96115} // namespace WebKit
     116
     117#endif
  • trunk/WebKit/chromium/src/WebViewImpl.cpp

    r54535 r54586  
    3232#include "WebViewImpl.h"
    3333
     34#include "AutoFillPopupMenuClient.h"
    3435#include "AutocompletePopupMenuClient.h"
    3536#include "AXObjectCache.h"
     
    241242    , m_dragOperation(WebDragOperationNone)
    242243    , m_suggestionsPopupShowing(false)
     244    , m_suggestionsPopupClient(0)
     245    , m_suggestionsPopup(0)
    243246    , m_isTransparent(false)
    244247    , m_tabsToLinks(false)
     
    469472    m_suppressNextKeypressEvent = false;
    470473
    471     // Give autocomplete a chance to consume the key events it is interested in.
     474    // Give Autocomplete a chance to consume the key events it is interested in.
    472475    if (autocompleteHandleKeyEvent(event))
    473476        return true;
     
    542545        // Update the entries in the currently showing popup to reflect the
    543546        // deletion.
    544         m_autocompletePopupClient->removeItemAtIndex(selectedIndex);
     547        m_autocompletePopupClient->removeSuggestionAtIndex(selectedIndex);
    545548        refreshSuggestionsPopup();
    546549        return false;
     
    15611564    int defaultSuggestionIndex)
    15621565{
     1566    applyAutocompleteSuggestions(node, suggestions, defaultSuggestionIndex);
     1567}
     1568
     1569void WebViewImpl::applyAutoFillSuggestions(
     1570    const WebNode& node,
     1571    const WebVector<WebString>& names,
     1572    const WebVector<WebString>& labels,
     1573    int defaultSuggestionIndex)
     1574{
     1575    ASSERT(names.size() == labels.size());
     1576    ASSERT(defaultSuggestionIndex < static_cast<int>(names.size()));
     1577
     1578    if (names.isEmpty()) {
     1579        hideSuggestionsPopup();
     1580        return;
     1581    }
     1582
     1583    RefPtr<Node> focusedNode = focusedWebCoreNode();
     1584    // If the node for which we queried the AutoFill suggestions is not the
     1585    // focused node, then we have nothing to do.  FIXME: also check the
     1586    // caret is at the end and that the text has not changed.
     1587    if (!focusedNode || focusedNode != PassRefPtr<Node>(node)) {
     1588        hideSuggestionsPopup();
     1589        return;
     1590    }
     1591
     1592    HTMLInputElement* inputElem =
     1593        static_cast<HTMLInputElement*>(focusedNode.get());
     1594
     1595    // The first time the AutoFill popup is shown we'll create the client and
     1596    // the popup.
     1597    if (!m_autoFillPopupClient.get())
     1598        m_autoFillPopupClient.set(new AutoFillPopupMenuClient);
     1599
     1600    m_autoFillPopupClient->initialize(inputElem, names, labels,
     1601                                      defaultSuggestionIndex);
     1602
     1603    if (m_suggestionsPopupClient != m_autoFillPopupClient.get()) {
     1604        hideSuggestionsPopup();
     1605        m_suggestionsPopupClient = m_autoFillPopupClient.get();
     1606    }
     1607
     1608    if (!m_autoFillPopup.get()) {
     1609        m_autoFillPopup = PopupContainer::create(m_suggestionsPopupClient,
     1610                                                 suggestionsPopupSettings);
     1611    }
     1612
     1613    if (m_suggestionsPopup != m_autoFillPopup.get())
     1614        m_suggestionsPopup = m_autoFillPopup.get();
     1615
     1616    if (m_suggestionsPopupShowing) {
     1617        m_autoFillPopupClient->setSuggestions(names, labels);
     1618        refreshSuggestionsPopup();
     1619    } else {
     1620        m_suggestionsPopup->show(focusedNode->getRect(),
     1621                                 focusedNode->ownerDocument()->view(), 0);
     1622        m_suggestionsPopupShowing = true;
     1623    }
     1624}
     1625
     1626void WebViewImpl::applyAutocompleteSuggestions(
     1627    const WebNode& node,
     1628    const WebVector<WebString>& suggestions,
     1629    int defaultSuggestionIndex)
     1630{
     1631    ASSERT(defaultSuggestionIndex < static_cast<int>(suggestions.size()));
     1632
    15631633    if (!m_page.get() || suggestions.isEmpty()) {
    15641634        hideSuggestionsPopup();
     
    15661636    }
    15671637
    1568     ASSERT(defaultSuggestionIndex < static_cast<int>(suggestions.size()));
    1569 
    1570     if (RefPtr<Frame> focused = m_page->focusController()->focusedFrame()) {
    1571         RefPtr<Document> document = focused->document();
    1572         if (!document.get()) {
    1573             hideSuggestionsPopup();
    1574             return;
    1575         }
    1576 
    1577         RefPtr<Node> focusedNode = document->focusedNode();
    1578         // If the node for which we queried the autofill suggestions is not the
    1579         // focused node, then we have nothing to do.  FIXME: also check the
    1580         // carret is at the end and that the text has not changed.
    1581         if (!focusedNode.get() || focusedNode != PassRefPtr<Node>(node)) {
    1582             hideSuggestionsPopup();
    1583             return;
    1584         }
    1585 
    1586         if (!focusedNode->hasTagName(HTMLNames::inputTag)) {
    1587             ASSERT_NOT_REACHED();
    1588             return;
    1589         }
    1590 
    1591         HTMLInputElement* inputElem =
    1592             static_cast<HTMLInputElement*>(focusedNode.get());
    1593 
    1594         // The first time the suggestions popup is shown we'll create the client
    1595         // and the popup.
    1596         if (!m_autocompletePopupClient.get())
    1597             m_autocompletePopupClient.set(new AutocompletePopupMenuClient(this));
    1598         m_autocompletePopupClient->initialize(inputElem,
    1599                                               suggestions,
    1600                                               defaultSuggestionIndex);
    1601         if (!m_suggestionsPopup.get()) {
    1602             m_suggestionsPopup =
    1603                 PopupContainer::create(m_autocompletePopupClient.get(),
    1604                                        suggestionsPopupSettings);
    1605         }
    1606 
    1607         if (m_suggestionsPopupShowing) {
    1608             m_autocompletePopupClient->setSuggestions(suggestions);
    1609             refreshSuggestionsPopup();
    1610         } else {
    1611             m_suggestionsPopup->show(focusedNode->getRect(),
    1612                                      focusedNode->ownerDocument()->view(), 0);
    1613             m_suggestionsPopupShowing = true;
    1614         }
     1638    RefPtr<Node> focusedNode = focusedWebCoreNode();
     1639    // If the node for which we queried the Autocomplete suggestions is not the
     1640    // focused node, then we have nothing to do.  FIXME: also check the
     1641    // caret is at the end and that the text has not changed.
     1642    if (!focusedNode || focusedNode != PassRefPtr<Node>(node)) {
     1643        hideSuggestionsPopup();
     1644        return;
     1645    }
     1646
     1647    HTMLInputElement* inputElem =
     1648        static_cast<HTMLInputElement*>(focusedNode.get());
     1649
     1650    // The first time the Autocomplete is shown we'll create the client and the
     1651    // popup.
     1652    if (!m_autocompletePopupClient.get())
     1653        m_autocompletePopupClient.set(new AutocompletePopupMenuClient);
     1654
     1655    m_autocompletePopupClient->initialize(inputElem, suggestions,
     1656                                          defaultSuggestionIndex);
     1657
     1658    if (m_suggestionsPopupClient != m_autocompletePopupClient.get()) {
     1659        hideSuggestionsPopup();
     1660        m_suggestionsPopupClient = m_autocompletePopupClient.get();
     1661    }
     1662
     1663    if (!m_autocompletePopup.get()) {
     1664        m_autocompletePopup = PopupContainer::create(m_suggestionsPopupClient,
     1665                                                     suggestionsPopupSettings);
     1666    }
     1667
     1668    if (m_suggestionsPopup != m_autocompletePopup.get())
     1669        m_suggestionsPopup = m_autocompletePopup.get();
     1670
     1671    if (m_suggestionsPopupShowing) {
     1672        m_autocompletePopupClient->setSuggestions(suggestions);
     1673        refreshSuggestionsPopup();
     1674    } else {
     1675        m_suggestionsPopup->show(focusedNode->getRect(),
     1676                                 focusedNode->ownerDocument()->view(), 0);
     1677        m_suggestionsPopupShowing = true;
    16151678    }
    16161679}
  • trunk/WebKit/chromium/src/WebViewImpl.h

    r54458 r54586  
    5959class PlatformKeyboardEvent;
    6060class PopupContainer;
     61class PopupMenuClient;
    6162class Range;
    6263class RenderTheme;
     
    6667namespace WebKit {
    6768class AutocompletePopupMenuClient;
     69class AutoFillPopupMenuClient;
    6870class ContextMenuClientImpl;
     71class SuggestionsPopupMenuClient;
    6972class WebAccessibilityObject;
    7073class WebDevToolsAgentPrivate;
     
    154157        const WebVector<WebString>& suggestions,
    155158        int defaultSuggestionIndex);
     159    virtual void applyAutoFillSuggestions(
     160        const WebNode&,
     161        const WebVector<WebString>& names,
     162        const WebVector<WebString>& labels,
     163        int defaultSuggestionIndex);
     164    virtual void applyAutocompleteSuggestions(
     165        const WebNode&,
     166        const WebVector<WebString>& suggestions,
     167        int defaultSuggestionIndex);
    156168    virtual void hideAutofillPopup();
    157169    virtual void hideSuggestionsPopup();
     
    396408    WebDragOperation m_dragOperation;
    397409
    398     // The suggestions popup.  Kept around and reused every-time new suggestions
    399     // should be shown.
    400     RefPtr<WebCore::PopupContainer> m_suggestionsPopup;
    401 
    402     // Whether the suggestions popup is currently showing.
     410    // Whether a suggestions popup is currently showing.
    403411    bool m_suggestionsPopupShowing;
    404412
    405     // The autocomplete client.
     413    // A pointer to the current suggestions popup menu client.  This can be
     414    // either an AutoFillPopupMenuClient or an AutocompletePopupMenuClient.  We
     415    // do not own this pointer.
     416    SuggestionsPopupMenuClient* m_suggestionsPopupClient;
     417
     418    // The AutoFill popup client.
     419    OwnPtr<AutoFillPopupMenuClient> m_autoFillPopupClient;
     420
     421    // The Autocomplete popup client.
    406422    OwnPtr<AutocompletePopupMenuClient> m_autocompletePopupClient;
     423
     424    // A pointer to the current suggestions popup.  We do not own this pointer.
     425    WebCore::PopupContainer* m_suggestionsPopup;
     426
     427    // The AutoFill suggestions popup.
     428    RefPtr<WebCore::PopupContainer> m_autoFillPopup;
     429
     430    // The AutoComplete suggestions popup.
     431    RefPtr<WebCore::PopupContainer> m_autocompletePopup;
    407432
    408433    OwnPtr<WebDevToolsAgentPrivate> m_devToolsAgent;
Note: See TracChangeset for help on using the changeset viewer.