This source file includes following definitions.
- didChooseValue
- didChooseValue
- didCancelChooser
- create
- toWebDateTimeInputType
- openDateTimeChooser
- didChooseValue
- didChooseValue
- didCancelChooser
- endChooser
#include "config.h"
#if !ENABLE(INPUT_MULTIPLE_FIELDS_UI)
#include "ExternalDateTimeChooser.h"
#include "ChromeClientImpl.h"
#include "InputTypeNames.h"
#include "WebDateTimeChooserCompletion.h"
#include "WebDateTimeChooserParams.h"
#include "WebViewClient.h"
#include "platform/DateTimeChooserClient.h"
#include "wtf/text/AtomicString.h"
using namespace WebCore;
namespace blink {
class WebDateTimeChooserCompletionImpl : public WebDateTimeChooserCompletion {
public:
WebDateTimeChooserCompletionImpl(ExternalDateTimeChooser* chooser)
: m_chooser(chooser)
{
}
private:
virtual void didChooseValue(const WebString& value) OVERRIDE
{
m_chooser->didChooseValue(value);
delete this;
}
virtual void didChooseValue(double value) OVERRIDE
{
m_chooser->didChooseValue(value);
delete this;
}
virtual void didCancelChooser() OVERRIDE
{
m_chooser->didCancelChooser();
delete this;
}
RefPtr<ExternalDateTimeChooser> m_chooser;
};
ExternalDateTimeChooser::~ExternalDateTimeChooser()
{
}
ExternalDateTimeChooser::ExternalDateTimeChooser(WebCore::DateTimeChooserClient* client)
: m_client(client)
{
ASSERT(client);
}
PassRefPtr<ExternalDateTimeChooser> ExternalDateTimeChooser::create(ChromeClientImpl* chromeClient, WebViewClient* webViewClient, WebCore::DateTimeChooserClient* client, const WebCore::DateTimeChooserParameters& parameters)
{
ASSERT(chromeClient);
RefPtr<ExternalDateTimeChooser> chooser = adoptRef(new ExternalDateTimeChooser(client));
if (!chooser->openDateTimeChooser(chromeClient, webViewClient, parameters))
chooser.clear();
return chooser.release();
}
static WebDateTimeInputType toWebDateTimeInputType(const AtomicString& source)
{
if (source == InputTypeNames::date)
return WebDateTimeInputTypeDate;
if (source == InputTypeNames::datetime)
return WebDateTimeInputTypeDateTime;
if (source == InputTypeNames::datetime_local)
return WebDateTimeInputTypeDateTimeLocal;
if (source == InputTypeNames::month)
return WebDateTimeInputTypeMonth;
if (source == InputTypeNames::time)
return WebDateTimeInputTypeTime;
if (source == InputTypeNames::week)
return WebDateTimeInputTypeWeek;
return WebDateTimeInputTypeNone;
}
bool ExternalDateTimeChooser::openDateTimeChooser(ChromeClientImpl* chromeClient, WebViewClient* webViewClient, const DateTimeChooserParameters& parameters)
{
if (!webViewClient)
return false;
WebDateTimeChooserParams webParams;
webParams.type = toWebDateTimeInputType(parameters.type);
webParams.anchorRectInScreen = chromeClient->rootViewToScreen(parameters.anchorRectInRootView);
webParams.currentValue = parameters.currentValue;
webParams.doubleValue = parameters.doubleValue;
webParams.suggestions = parameters.suggestions;
webParams.minimum = parameters.minimum;
webParams.maximum = parameters.maximum;
webParams.step = parameters.step;
webParams.stepBase = parameters.stepBase;
webParams.isRequired = parameters.required;
webParams.isAnchorElementRTL = parameters.isAnchorElementRTL;
WebDateTimeChooserCompletion* completion = new WebDateTimeChooserCompletionImpl(this);
if (webViewClient->openDateTimeChooser(webParams, completion))
return true;
completion->didCancelChooser();
return false;
}
void ExternalDateTimeChooser::didChooseValue(const WebString& value)
{
if (m_client)
m_client->didChooseValue(value);
if (m_client)
m_client->didEndChooser();
}
void ExternalDateTimeChooser::didChooseValue(double value)
{
if (m_client)
m_client->didChooseValue(value);
if (m_client)
m_client->didEndChooser();
}
void ExternalDateTimeChooser::didCancelChooser()
{
if (m_client)
m_client->didEndChooser();
}
void ExternalDateTimeChooser::endChooser()
{
DateTimeChooserClient* client = m_client;
m_client = 0;
client->didEndChooser();
}
}
#endif