Commit b8f608b0 authored by keishi@webkit.org's avatar keishi@webkit.org

Move PagePopupClient implementation for input[type=date] to Chromium WebKit layer

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

Reviewed by Kent Tamura.

Source/WebCore:

We are moving calendar picker PagePopupClient to WebKit layer so ports
can use their platform native chooser UI if they have one.
DateTimeChooser, DateTimeChooserClient etc. will be reused when we
implement the week picker and month picker.

No new tests. No behavior change. Covered by existing calendar picker tests.

* WebCore.gypi:
* html/shadow/CalendarPickerElement.cpp:
(WebCore::CalendarPickerElement::CalendarPickerElement):
(WebCore::CalendarPickerElement::~CalendarPickerElement):
(WebCore::CalendarPickerElement::didChooseValue): Called when user chose a value.
(WebCore):
(WebCore::CalendarPickerElement::didEndChooser): Called when chooser has ended.
(WebCore::CalendarPickerElement::openPopup):
(WebCore::CalendarPickerElement::closePopup):
* html/shadow/CalendarPickerElement.h:
(CalendarPickerElement):
* loader/EmptyClients.cpp:
(WebCore):
(WebCore::EmptyChromeClient::openDateTimeChooser):
* loader/EmptyClients.h:
(EmptyChromeClient):
* page/ChromeClient.h:
(WebCore):
(ChromeClient):
* platform/DateTimeChooser.h:
(WebCore):
(DateTimeChooserParameters): Contains information needed to open the DateTimeChooser.
(DateTimeChooser):
(WebCore::DateTimeChooser::~DateTimeChooser):
* platform/DateTimeChooserClient.h:
(WebCore):
(DateTimeChooserClient):
(WebCore::DateTimeChooserClient::~DateTimeChooserClient):

Source/WebKit/chromium:

* WebKit.gyp:
* src/ChromeClientImpl.cpp:
(WebKit):
(WebKit::ChromeClientImpl::openDateTimeChooser):
* src/ChromeClientImpl.h:
(WebCore):
(ChromeClientImpl):
* src/DateTimeChooserImpl.cpp: Added.
(WebKit):
(WebKit::DateTimeChooserImpl::DateTimeChooserImpl):
(WebKit::DateTimeChooserImpl::~DateTimeChooserImpl):
(WebKit::DateTimeChooserImpl::endChooser):
(WebKit::DateTimeChooserImpl::contentSize):
(WebKit::DateTimeChooserImpl::writeDocument):
(WebKit::DateTimeChooserImpl::setValueAndClosePopup):
(WebKit::DateTimeChooserImpl::didClosePopup):
* src/DateTimeChooserImpl.h:
(WebCore):
(WebKit):
(DateTimeChooserImpl):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@127558 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent f9e8a8df
2012-09-04 Keishi Hattori <keishi@webkit.org>
Move PagePopupClient implementation for input[type=date] to Chromium WebKit layer
https://bugs.webkit.org/show_bug.cgi?id=95681
Reviewed by Kent Tamura.
We are moving calendar picker PagePopupClient to WebKit layer so ports
can use their platform native chooser UI if they have one.
DateTimeChooser, DateTimeChooserClient etc. will be reused when we
implement the week picker and month picker.
No new tests. No behavior change. Covered by existing calendar picker tests.
* WebCore.gypi:
* html/shadow/CalendarPickerElement.cpp:
(WebCore::CalendarPickerElement::CalendarPickerElement):
(WebCore::CalendarPickerElement::~CalendarPickerElement):
(WebCore::CalendarPickerElement::didChooseValue): Called when user chose a value.
(WebCore):
(WebCore::CalendarPickerElement::didEndChooser): Called when chooser has ended.
(WebCore::CalendarPickerElement::openPopup):
(WebCore::CalendarPickerElement::closePopup):
* html/shadow/CalendarPickerElement.h:
(CalendarPickerElement):
* loader/EmptyClients.cpp:
(WebCore):
(WebCore::EmptyChromeClient::openDateTimeChooser):
* loader/EmptyClients.h:
(EmptyChromeClient):
* page/ChromeClient.h:
(WebCore):
(ChromeClient):
* platform/DateTimeChooser.h:
(WebCore):
(DateTimeChooserParameters): Contains information needed to open the DateTimeChooser.
(DateTimeChooser):
(WebCore::DateTimeChooser::~DateTimeChooser):
* platform/DateTimeChooserClient.h:
(WebCore):
(DateTimeChooserClient):
(WebCore::DateTimeChooserClient::~DateTimeChooserClient):
2012-09-04 Mike Lawther <mikelawther@chromium.org>
CSS3 calc: expressions with 'em' units do not zoom correctly.
......@@ -337,6 +337,8 @@
'platform/ThreadGlobalData.h',
'platform/Timer.h',
'platform/TreeShared.h',
'platform/DateTimeChooser.h',
'platform/DateTimeChooserClient.h',
'platform/VisitedLinkStrategy.h',
'platform/VisitedLinks.h',
'platform/Widget.h',
......
......@@ -33,22 +33,13 @@
#if ENABLE(CALENDAR_PICKER)
#include "CalendarPicker.h"
#include "Chrome.h"
#include "ChromeClient.h"
#include "DateComponents.h"
#include "Event.h"
#include "FrameView.h"
#include "HTMLInputElement.h"
#include "HTMLNames.h"
#include "Language.h"
#include "LocalizedDate.h"
#include "LocalizedStrings.h"
#include "Page.h"
#include "PickerCommon.h"
#include "RenderDetailsMarker.h"
#include "RenderTheme.h"
#include <wtf/text/StringBuilder.h>
using namespace WTF::Unicode;
......@@ -58,7 +49,7 @@ using namespace HTMLNames;
inline CalendarPickerElement::CalendarPickerElement(Document* document)
: HTMLDivElement(divTag, document)
, m_popup(0)
, m_chooser(nullptr)
{
setShadowPseudoId("-webkit-calendar-picker-indicator");
}
......@@ -71,7 +62,7 @@ PassRefPtr<CalendarPickerElement> CalendarPickerElement::create(Document* docume
CalendarPickerElement::~CalendarPickerElement()
{
closePopup();
ASSERT(!m_popup);
ASSERT(!m_chooser);
}
RenderObject* CalendarPickerElement::createRenderer(RenderArena* arena, RenderStyle*)
......@@ -114,9 +105,19 @@ bool CalendarPickerElement::willRespondToMouseClickEvents()
return HTMLDivElement::willRespondToMouseClickEvents();
}
void CalendarPickerElement::didChooseValue(const String& value)
{
hostInput()->setValue(value, DispatchChangeEvent);
}
void CalendarPickerElement::didEndChooser()
{
m_chooser.clear();
}
void CalendarPickerElement::openPopup()
{
if (m_popup)
if (m_chooser)
return;
if (!document()->page())
return;
......@@ -125,20 +126,29 @@ void CalendarPickerElement::openPopup()
return;
if (!document()->view())
return;
IntRect elementRectInRootView = document()->view()->contentsToRootView(hostInput()->getPixelSnappedRect());
m_popup = chrome->client()->openPagePopup(this, elementRectInRootView);
HTMLInputElement* input = hostInput();
DateTimeChooserParameters parameters;
parameters.type = input->type();
parameters.minimum = input->minimum();
parameters.maximum = input->maximum();
parameters.required = input->required();
Decimal step;
if (hostInput()->getAllowedValueStep(&step))
parameters.step = 1.0;
else
parameters.step = step.toDouble();
parameters.anchorRectInRootView = document()->view()->contentsToRootView(hostInput()->getPixelSnappedRect());
parameters.currentValue = input->value();
// FIXME: parameters.suggestionValues and suggestionLabels will be used when we support datalist.
m_chooser = chrome->client()->openDateTimeChooser(this, parameters);
}
void CalendarPickerElement::closePopup()
{
if (!m_popup)
return;
if (!document()->page())
if (!m_chooser)
return;
Chrome* chrome = document()->page()->chrome();
if (!chrome)
return;
chrome->client()->closePagePopup(m_popup);
m_chooser->endChooser();
}
void CalendarPickerElement::detach()
......@@ -147,67 +157,6 @@ void CalendarPickerElement::detach()
HTMLDivElement::detach();
}
IntSize CalendarPickerElement::contentSize()
{
return IntSize(0, 0);
}
void CalendarPickerElement::writeDocument(DocumentWriter& writer)
{
HTMLInputElement* input = hostInput();
DateComponents date;
date.setMillisecondsSinceEpochForDate(input->minimum());
String minString = date.toString();
date.setMillisecondsSinceEpochForDate(input->maximum());
String maxString = date.toString();
Decimal step;
String stepString = input->fastGetAttribute(stepAttr);
if (stepString.isEmpty() || !input->getAllowedValueStep(&step))
stepString = "1";
addString("<!DOCTYPE html><head><meta charset='UTF-8'><style>\n", writer);
writer.addData(pickerCommonCss, sizeof(pickerCommonCss));
writer.addData(calendarPickerCss, sizeof(calendarPickerCss));
if (document()->page()) {
CString extraStyle = document()->page()->theme()->extraCalendarPickerStyleSheet();
if (extraStyle.length())
writer.addData(extraStyle.data(), extraStyle.length());
}
addString("</style></head><body><div id=main>Loading...</div><script>\n"
"window.dialogArguments = {\n", writer);
addProperty("min", minString, writer);
addProperty("max", maxString, writer);
addProperty("step", stepString, writer);
addProperty("required", input->required(), writer);
addProperty("currentValue", input->value(), writer);
addProperty("locale", defaultLanguage(), writer);
addProperty("todayLabel", calendarTodayText(), writer);
addProperty("clearLabel", calendarClearText(), writer);
addProperty("weekStartDay", firstDayOfWeek(), writer);
addProperty("monthLabels", monthLabels(), writer);
addProperty("dayLabels", weekDayShortLabels(), writer);
Direction dir = direction(monthLabels()[0][0]);
addProperty("isRTL", dir == RightToLeft || dir == RightToLeftArabic, writer);
addString("}\n", writer);
writer.addData(pickerCommonJs, sizeof(pickerCommonJs));
writer.addData(calendarPickerJs, sizeof(calendarPickerJs));
addString("</script></body>\n", writer);
}
void CalendarPickerElement::setValueAndClosePopup(int numValue, const String& stringValue)
{
ASSERT(m_popup);
closePopup();
if (numValue >= 0)
hostInput()->setValue(stringValue, DispatchChangeEvent);
}
void CalendarPickerElement::didClosePopup()
{
m_popup = 0;
}
}
#endif
......@@ -32,15 +32,18 @@
#define CalendarPickerElement_h
#if ENABLE(CALENDAR_PICKER)
#include "DateTimeChooser.h"
#include "DateTimeChooserClient.h"
#include "HTMLDivElement.h"
#include "PagePopupClient.h"
#include <wtf/OwnPtr.h>
namespace WebCore {
class HTMLInputElement;
class PagePopup;
class CalendarPickerElement : public HTMLDivElement, public PagePopupClient {
class CalendarPickerElement : public HTMLDivElement, public DateTimeChooserClient {
public:
static PassRefPtr<CalendarPickerElement> create(Document*);
virtual ~CalendarPickerElement();
......@@ -48,21 +51,19 @@ public:
void closePopup();
virtual bool willRespondToMouseClickEvents() OVERRIDE;
// DateTimeChooserClient implementation.
virtual void didChooseValue(const String&) OVERRIDE;
virtual void didEndChooser() OVERRIDE;
private:
CalendarPickerElement(Document*);
virtual RenderObject* createRenderer(RenderArena*, RenderStyle*) OVERRIDE;
virtual void defaultEventHandler(Event*) OVERRIDE;
virtual void detach() OVERRIDE;
// PagePopupClient functions:
virtual IntSize contentSize() OVERRIDE;
virtual void writeDocument(DocumentWriter&) OVERRIDE;
virtual void setValueAndClosePopup(int, const String&) OVERRIDE;
virtual void didClosePopup() OVERRIDE;
HTMLInputElement* hostInput();
PagePopup* m_popup;
OwnPtr<DateTimeChooser> m_chooser;
};
}
......
......@@ -28,6 +28,7 @@
#include "config.h"
#include "EmptyClients.h"
#include "DateTimeChooser.h"
#include "DocumentLoader.h"
#include "FileChooser.h"
#include "FormState.h"
......@@ -103,6 +104,13 @@ PassOwnPtr<ColorChooser> EmptyChromeClient::createColorChooser(ColorChooserClien
}
#endif
#if ENABLE(CALENDAR_PICKER)
PassOwnPtr<DateTimeChooser> EmptyChromeClient::openDateTimeChooser(DateTimeChooserClient*, const DateTimeChooserParameters&)
{
return nullptr;
}
#endif
void EmptyChromeClient::runOpenPanel(Frame*, PassRefPtr<FileChooser>)
{
}
......
......@@ -172,6 +172,10 @@ public:
virtual PassOwnPtr<ColorChooser> createColorChooser(ColorChooserClient*, const Color&) OVERRIDE;
#endif
#if ENABLE(CALENDAR_PICKER)
virtual PassOwnPtr<DateTimeChooser> openDateTimeChooser(DateTimeChooserClient*, const DateTimeChooserParameters&) OVERRIDE;
#endif
virtual void runOpenPanel(Frame*, PassRefPtr<FileChooser>) OVERRIDE;
virtual void loadIconForFiles(const Vector<String>&, FileIconLoader*) { }
......
......@@ -48,6 +48,8 @@ class NSResponder;
namespace WebCore {
class AccessibilityObject;
class DateTimeChooser;
class DateTimeChooserClient;
class Element;
class FileChooser;
class FileIconLoader;
......@@ -69,6 +71,7 @@ namespace WebCore {
class GraphicsContext3D;
class Widget;
struct DateTimeChooserParameters;
struct FrameLoadRequest;
struct ViewportArguments;
struct WindowFeatures;
......@@ -222,6 +225,10 @@ namespace WebCore {
virtual PassOwnPtr<ColorChooser> createColorChooser(ColorChooserClient*, const Color&) = 0;
#endif
#if ENABLE(CALENDAR_PICKER)
virtual PassOwnPtr<DateTimeChooser> openDateTimeChooser(DateTimeChooserClient*, const DateTimeChooserParameters&) = 0;
#endif
virtual void runOpenPanel(Frame*, PassRefPtr<FileChooser>) = 0;
// Asynchronous request to load an icon for specified filenames.
virtual void loadIconForFiles(const Vector<String>&, FileIconLoader*) = 0;
......
/*
* Copyright (C) 2012 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef DateTimeChooser_h
#define DateTimeChooser_h
#include "IntRect.h"
#include <wtf/text/WTFString.h>
namespace WebCore {
struct DateTimeChooserParameters {
AtomicString type;
IntRect anchorRectInRootView;
String currentValue;
Vector<String> suggestionValues;
Vector<String> suggestionLabels;
double minimum;
double maximum;
double step;
bool required;
};
// For pickers like color pickers and date pickers.
class DateTimeChooser {
public:
virtual ~DateTimeChooser() { }
virtual void endChooser() = 0;
};
} // namespace WebCore
#endif // DateTimeChooser_h
/*
* Copyright (C) 2012 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef DateTimeChooserClient_h
#define DateTimeChooserClient_h
namespace WebCore {
class DateTimeChooserClient {
public:
virtual ~DateTimeChooserClient() { }
// Called when user picked a value.
virtual void didChooseValue(const String&) = 0;
// Called when chooser has ended.
virtual void didEndChooser() = 0;
};
} // namespace WebCore
#endif // DateTimeChooserClient_h
2012-09-04 Keishi Hattori <keishi@webkit.org>
Move PagePopupClient implementation for input[type=date] to Chromium WebKit layer
https://bugs.webkit.org/show_bug.cgi?id=95681
Reviewed by Kent Tamura.
* WebKit.gyp:
* src/ChromeClientImpl.cpp:
(WebKit):
(WebKit::ChromeClientImpl::openDateTimeChooser):
* src/ChromeClientImpl.h:
(WebCore):
(ChromeClientImpl):
* src/DateTimeChooserImpl.cpp: Added.
(WebKit):
(WebKit::DateTimeChooserImpl::DateTimeChooserImpl):
(WebKit::DateTimeChooserImpl::~DateTimeChooserImpl):
(WebKit::DateTimeChooserImpl::endChooser):
(WebKit::DateTimeChooserImpl::contentSize):
(WebKit::DateTimeChooserImpl::writeDocument):
(WebKit::DateTimeChooserImpl::setValueAndClosePopup):
(WebKit::DateTimeChooserImpl::didClosePopup):
* src/DateTimeChooserImpl.h:
(WebCore):
(WebKit):
(DateTimeChooserImpl):
2012-09-04 Adam Barth <abarth@chromium.org>
Make chromium-linux build without WTF_DEPRECATED_STRING_OPERATORS
......
......@@ -358,6 +358,8 @@
'src/BatteryClientImpl.h',
'src/BlobRegistryProxy.cpp',
'src/BlobRegistryProxy.h',
'src/DateTimeChooserImpl.cpp',
'src/DateTimeChooserImpl.h',
'src/ChromeClientImpl.cpp',
'src/ChromeClientImpl.h',
'src/ChromiumCurrentTime.cpp',
......
......@@ -42,6 +42,7 @@
#include "Console.h"
#include "Cursor.h"
#include "DatabaseTracker.h"
#include "DateTimeChooserImpl.h"
#include "Document.h"
#include "DocumentLoader.h"
#include "ExternalPopupMenu.h"
......@@ -704,6 +705,13 @@ PassOwnPtr<WebColorChooser> ChromeClientImpl::createWebColorChooser(WebColorChoo
}
#endif
#if ENABLE(CALENDAR_PICKER)
PassOwnPtr<WebCore::DateTimeChooser> ChromeClientImpl::openDateTimeChooser(WebCore::DateTimeChooserClient* pickerClient, const WebCore::DateTimeChooserParameters& parameters)
{
return adoptPtr(new DateTimeChooserImpl(this, pickerClient, parameters));
}
#endif
void ChromeClientImpl::runOpenPanel(Frame* frame, PassRefPtr<FileChooser> fileChooser)
{
WebViewClient* client = m_webView->client();
......
......@@ -50,6 +50,8 @@ class PopupContainer;
class PopupMenuClient;
class RenderBox;
class SecurityOrigin;
class DateTimeChooser;
class DateTimeChooserClient;
struct WindowFeatures;
}
......@@ -143,6 +145,9 @@ public:
#if ENABLE(INPUT_TYPE_COLOR)
virtual PassOwnPtr<WebCore::ColorChooser> createColorChooser(WebCore::ColorChooserClient*, const WebCore::Color&) OVERRIDE;
PassOwnPtr<WebColorChooser> createWebColorChooser(WebColorChooserClient*, const WebColor&);
#endif
#if ENABLE(CALENDAR_PICKER)
virtual PassOwnPtr<WebCore::DateTimeChooser> openDateTimeChooser(WebCore::DateTimeChooserClient*, const WebCore::DateTimeChooserParameters&) OVERRIDE;
#endif
virtual void runOpenPanel(WebCore::Frame*, PassRefPtr<WebCore::FileChooser>);
virtual void loadIconForFiles(const Vector<WTF::String>&, WebCore::FileIconLoader*);
......
/*
* Copyright (C) 2012 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include "DateTimeChooserImpl.h"
#if ENABLE(CALENDAR_PICKER)
#include "CalendarPicker.h"
#include "ChromeClientImpl.h"
#include "DateComponents.h"
#include "DateTimeChooserClient.h"
#include "Language.h"
#include "LocalizedDate.h"
#include "NotImplemented.h"
#include "PickerCommon.h"
#include "RenderTheme.h"
#include "platform/WebKitPlatformSupport.h"
#include <public/WebLocalizedString.h>
using namespace WTF::Unicode;
namespace WebKit {
DateTimeChooserImpl::DateTimeChooserImpl(ChromeClientImpl* chromeClient, WebCore::DateTimeChooserClient* client, const WebCore::DateTimeChooserParameters& parameters)
: m_chromeClient(chromeClient)
, m_client(client)
, m_popup(0)
, m_parameters(parameters)
{
ASSERT(m_chromeClient);
ASSERT(m_client);
m_popup = m_chromeClient->openPagePopup(this, m_parameters.anchorRectInRootView);
}
DateTimeChooserImpl::~DateTimeChooserImpl()
{
}
void DateTimeChooserImpl::endChooser()
{
if (!m_popup)
return;
m_chromeClient->closePagePopup(m_popup);
}
WebCore::IntSize DateTimeChooserImpl::contentSize()
{
return WebCore::IntSize(0, 0);
}
void DateTimeChooserImpl::writeDocument(WebCore::DocumentWriter& writer)
{
WebCore::DateComponents date;
date.setMillisecondsSinceEpochForDate(m_parameters.minimum);
String minString = date.toString();
date.setMillisecondsSinceEpochForDate(m_parameters.maximum);
String maxString = date.toString();
String stepString = String::number(m_parameters.step);
addString("<!DOCTYPE html><head><meta charset='UTF-8'><style>\n", writer);
writer.addData(WebCore::pickerCommonCss, sizeof(WebCore::pickerCommonCss));
writer.addData(WebCore::calendarPickerCss, sizeof(WebCore::calendarPickerCss));
CString extraStyle = WebCore::RenderTheme::defaultTheme()->extraCalendarPickerStyleSheet();
if (extraStyle.length())
writer.addData(extraStyle.data(), extraStyle.length());
addString("</style></head><body><div id=main>Loading...</div><script>\n"
"window.dialogArguments = {\n", writer);
addProperty("min", minString, writer);
addProperty("max", maxString, writer);
addProperty("step", stepString, writer);
addProperty("required", m_parameters.required, writer);
addProperty("currentValue", m_parameters.currentValue, writer);
addProperty("locale", WebCore::defaultLanguage(), writer);
addProperty("todayLabel", Platform::current()->queryLocalizedString(WebLocalizedString::CalendarToday), writer);
addProperty("clearLabel", Platform::current()->queryLocalizedString(WebLocalizedString::CalendarClear), writer);
addProperty("weekStartDay", WebCore::firstDayOfWeek(), writer);
addProperty("monthLabels", WebCore::monthLabels(), writer);
addProperty("dayLabels", WebCore::weekDayShortLabels(), writer);
Direction dir = direction(WebCore::monthLabels()[0][0]);
addProperty("isRTL", dir == RightToLeft || dir == RightToLeftArabic, writer);
addString("}\n", writer);
writer.addData(WebCore::pickerCommonJs, sizeof(WebCore::pickerCommonJs));
writer.addData(WebCore::calendarPickerJs, sizeof(WebCore::calendarPickerJs));
addString("</script></body>\n", writer);
}
void DateTimeChooserImpl::setValueAndClosePopup(int numValue, const String& stringValue)
{
if (numValue >= 0)
m_client->didChooseValue(stringValue);
endChooser();
}
void DateTimeChooserImpl::didClosePopup()
{
m_client->didEndChooser();
m_popup = 0;
}
} // namespace WebKit
#endif // ENABLE(CALENDAR_PICKER)
/*
* Copyright (C) 2012 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer