This source file includes following definitions.
- adjustInputFieldSpeechButtonStyle
- paintInputFieldSpeechButton
#include "config.h"
#if ENABLE(INPUT_SPEECH)
#include "core/rendering/RenderInputSpeech.h"
#include "core/html/shadow/TextControlInnerElements.h"
#include "core/rendering/PaintInfo.h"
#include "core/rendering/RenderBox.h"
#include "platform/graphics/GraphicsContext.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(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());
DEFINE_STATIC_REF(Image, imageStateNormal, (Image::loadPlatformResource("inputSpeech")));
DEFINE_STATIC_REF(Image, imageStateRecording, (Image::loadPlatformResource("inputSpeechRecording")));
DEFINE_STATIC_REF(Image, imageStateWaiting, (Image::loadPlatformResource("inputSpeechWaiting")));
InputFieldSpeechButtonElement* speechButton = toInputFieldSpeechButtonElement(element);
Image* image = imageStateNormal;
if (speechButton->state() == InputFieldSpeechButtonElement::Recording)
image = imageStateRecording;
else if (speechButton->state() == InputFieldSpeechButtonElement::Recognizing)
image = imageStateWaiting;
paintInfo.context->drawImage(image, pixelSnappedIntRect(buttonRect));
return false;
}
}
#endif