summaryrefslogtreecommitdiffstats
path: root/chrome/renderer/validation_message_agent.cc
blob: ef4c504d980de62e95e0b98ec609860d7b8dda8e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/renderer/validation_message_agent.h"

#include "base/i18n/rtl.h"
#include "chrome/common/validation_message_messages.h"
#include "content/public/renderer/render_view.h"
#include "third_party/WebKit/public/web/WebView.h"

ValidationMessageAgent::ValidationMessageAgent(content::RenderView* render_view)
    : content::RenderViewObserver(render_view)
{
  render_view->GetWebView()->setValidationMessageClient(this);
}

ValidationMessageAgent::~ValidationMessageAgent() {}

void ValidationMessageAgent::showValidationMessage(
    const WebKit::WebRect& anchor_in_root_view,
    const WebKit::WebString& main_text,
    const WebKit::WebString& sub_text,
    WebKit::WebTextDirection hint) {
  string16 wrapped_main_text = main_text;
  string16 wrapped_sub_text = sub_text;
  if (hint == WebKit::WebTextDirectionLeftToRight) {
    wrapped_main_text
        = base::i18n::GetDisplayStringInLTRDirectionality(wrapped_main_text);
    if (!wrapped_sub_text.empty()) {
      wrapped_sub_text
          = base::i18n::GetDisplayStringInLTRDirectionality(wrapped_sub_text);
    }
  } else if (hint == WebKit::WebTextDirectionRightToLeft
             && !base::i18n::IsRTL()) {
    base::i18n::WrapStringWithRTLFormatting(&wrapped_main_text);
    if (!wrapped_sub_text.empty()) {
      base::i18n::WrapStringWithRTLFormatting(&wrapped_sub_text);
    }
  }

  Send(new ValidationMessageMsg_ShowValidationMessage(
      routing_id(), anchor_in_root_view, wrapped_main_text, wrapped_sub_text));
}

void ValidationMessageAgent::hideValidationMessage() {
  Send(new ValidationMessageMsg_HideValidationMessage());
}

void ValidationMessageAgent::moveValidationMessage(
      const WebKit::WebRect& anchor_in_root_view) {
  Send(new ValidationMessageMsg_MoveValidationMessage(
      routing_id(), anchor_in_root_view));
}