SuggestionsPopupMenuClient.cpp [plain text]
#include "config.h"
#include "SuggestionsPopupMenuClient.h"
#include "CSSStyleSelector.h"
#include "CSSValueKeywords.h"
#include "Chrome.h"
#include "FrameView.h"
#include "HTMLInputElement.h"
#include "RenderTheme.h"
#include "WebViewImpl.h"
using namespace WebCore;
namespace WebKit {
SuggestionsPopupMenuClient::SuggestionsPopupMenuClient()
: m_textField(0)
, m_selectedIndex(0)
{
}
SuggestionsPopupMenuClient::~SuggestionsPopupMenuClient()
{
}
void SuggestionsPopupMenuClient::valueChanged(unsigned listIndex, bool fireEvents)
{
m_textField->setValue(getSuggestion(listIndex));
WebViewImpl* webView = getWebView();
if (!webView)
return;
EditorClientImpl* editor =
static_cast<EditorClientImpl*>(webView->page()->editorClient());
ASSERT(editor);
editor->onAutocompleteSuggestionAccepted(
static_cast<HTMLInputElement*>(m_textField.get()));
}
String SuggestionsPopupMenuClient::itemText(unsigned listIndex) const
{
return getSuggestion(listIndex);
}
PopupMenuStyle SuggestionsPopupMenuClient::itemStyle(unsigned listIndex) const
{
return *m_style;
}
PopupMenuStyle SuggestionsPopupMenuClient::menuStyle() const
{
return *m_style;
}
int SuggestionsPopupMenuClient::clientPaddingLeft() const
{
RenderStyle* style = textFieldStyle();
if (!style)
return 0;
return RenderTheme::defaultTheme()->popupInternalPaddingLeft(style);
}
int SuggestionsPopupMenuClient::clientPaddingRight() const
{
RenderStyle* style = textFieldStyle();
if (!style)
return 0;
return RenderTheme::defaultTheme()->popupInternalPaddingRight(style);
}
void SuggestionsPopupMenuClient::popupDidHide()
{
WebViewImpl* webView = getWebView();
if (webView)
webView->suggestionsPopupDidHide();
}
void SuggestionsPopupMenuClient::setTextFromItem(unsigned listIndex)
{
m_textField->setValue(getSuggestion(listIndex));
}
FontSelector* SuggestionsPopupMenuClient::fontSelector() const
{
return m_textField->document()->styleSelector()->fontSelector();
}
HostWindow* SuggestionsPopupMenuClient::hostWindow() const
{
return m_textField->document()->view()->hostWindow();
}
PassRefPtr<Scrollbar> SuggestionsPopupMenuClient::createScrollbar(
ScrollbarClient* client,
ScrollbarOrientation orientation,
ScrollbarControlSize size)
{
return Scrollbar::createNativeScrollbar(client, orientation, size);
}
RenderStyle* SuggestionsPopupMenuClient::textFieldStyle() const
{
RenderStyle* style = m_textField->computedStyle();
if (!style) {
ASSERT_NOT_REACHED();
}
return style;
}
void SuggestionsPopupMenuClient::initialize(HTMLInputElement* textField,
int defaultSuggestionIndex)
{
m_textField = textField;
m_selectedIndex = defaultSuggestionIndex;
FontDescription fontDescription;
RenderTheme::defaultTheme()->systemFont(CSSValueWebkitControl,
fontDescription);
RenderStyle* style = m_textField->computedStyle();
fontDescription.setComputedSize(style->fontDescription().computedSize());
Font font(fontDescription, 0, 0);
font.update(textField->document()->styleSelector()->fontSelector());
m_style.set(new PopupMenuStyle(Color::black, Color::white, font, true,
Length(WebCore::Fixed),
textField->renderer()->style()->direction()));
}
WebViewImpl* SuggestionsPopupMenuClient::getWebView() const
{
Frame* frame = m_textField->document()->frame();
if (!frame)
return 0;
Page* page = frame->page();
if (!page)
return 0;
return static_cast<ChromeClientImpl*>(page->chrome()->client())->webView();
}
}