RenderInputSpeech.cpp [plain text]
#include "config.h"
#if ENABLE(INPUT_SPEECH)
#include "RenderInputSpeech.h"
#include "GraphicsContext.h"
#include "HTMLNames.h"
#include "PaintInfo.h"
#include "RenderBox.h"
#include "TextControlInnerElements.h"
namespace WebCore {
static const float defaultControlFontPixelSize = 13;
static const float defaultSpeechButtonSize = 16;
static const float minSpeechButtonSize = 8;
static const float maxSpeechButtonSize = 40;
void RenderInputSpeech::adjustInputFieldSpeechButtonStyle(StyleResolver*, RenderStyle* style, Element*)
{
float fontScale = style->fontSize() / defaultControlFontPixelSize;
int speechButtonSize = lroundf(std::min(std::max(minSpeechButtonSize, defaultSpeechButtonSize * fontScale), maxSpeechButtonSize));
style->setWidth(Length(speechButtonSize, Fixed));
style->setHeight(Length(speechButtonSize, Fixed));
}
bool RenderInputSpeech::paintInputFieldSpeechButton(RenderObject* object, const PaintInfo& paintInfo, const IntRect& rect)
{
Element* element = object->node()->isElementNode() ? toElement(object->node()) : 0;
if (!element || !element->isInputFieldSpeechButtonElement())
return false;
Node* input = object->node()->shadowHost();
if (!input->renderer()->isBox())
return false;
RenderBox* inputRenderBox = toRenderBox(input->renderer());
LayoutRect inputContentBox = inputRenderBox->contentBoxRect();
LayoutUnit buttonSize = std::min(inputContentBox.width(), std::min<LayoutUnit>(inputContentBox.height(), rect.height()));
LayoutRect buttonRect(object->offsetFromAncestorContainer(inputRenderBox).width(),
inputContentBox.y() + (inputContentBox.height() - buttonSize + 1) / 2,
buttonSize, buttonSize);
LayoutSize offsetFromInputRenderer = -(object->offsetFromAncestorContainer(inputRenderBox));
buttonRect.move(offsetFromInputRenderer);
buttonRect.moveBy(rect.location());
DEPRECATED_DEFINE_STATIC_LOCAL(RefPtr<Image>, imageStateNormal, (Image::loadPlatformResource("inputSpeech")));
DEPRECATED_DEFINE_STATIC_LOCAL(RefPtr<Image>, imageStateRecording, (Image::loadPlatformResource("inputSpeechRecording")));
DEPRECATED_DEFINE_STATIC_LOCAL(RefPtr<Image>, imageStateWaiting, (Image::loadPlatformResource("inputSpeechWaiting")));
InputFieldSpeechButtonElement* speechButton = toInputFieldSpeechButtonElement(element);
Image* image = imageStateNormal.get();
if (speechButton->state() == InputFieldSpeechButtonElement::Recording)
image = imageStateRecording.get();
else if (speechButton->state() == InputFieldSpeechButtonElement::Recognizing)
image = imageStateWaiting.get();
paintInfo.context->drawImage(image, object->style().colorSpace(), pixelSnappedIntRect(buttonRect));
return false;
}
}
#endif // ENABLE(INPUT_SPEECH)