// Copyright (c) 2011 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/browser/chromeos/login/textfield_with_margin.h"

#include "chrome/browser/chromeos/login/helper.h"
#include "ui/base/keycodes/keyboard_codes.h"

namespace {

// Holds ratio of the margin to the preferred text height.
const double kTextMarginRate = 0.33;

// Size of each vertical margin (top, bottom).
const int kVerticalMargin = 3;

}  // namespace

namespace chromeos {

TextfieldWithMargin::TextfieldWithMargin() {
  CorrectTextfieldFontSize(this);
}

TextfieldWithMargin::TextfieldWithMargin(views::Textfield::StyleFlags style)
    : Textfield(style) {
  CorrectTextfieldFontSize(this);
}

void TextfieldWithMargin::Layout() {
  int margin = GetPreferredSize().height() * kTextMarginRate;
  SetHorizontalMargins(margin, margin);
  SetVerticalMargins(kVerticalMargin, kVerticalMargin);
  views::Textfield::Layout();
}

bool TextfieldWithMargin::OnKeyPressed(const views::KeyEvent& e) {
  if (e.key_code() == ui::VKEY_ESCAPE && !text().empty()) {
    SetText(string16());
    return true;
  }
  return views::Textfield::OnKeyPressed(e);
}

}  // namespace chromeos

// Copyright (c) 2010 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/browser/chromeos/login/textfield_with_margin.h"

#include "chrome/browser/chromeos/login/helper.h"
#include "ui/base/keycodes/keyboard_codes.h"

namespace {

// Holds ratio of the margin to the preferred text height.
const double kTextMarginRate = 0.33;

// Size of each vertical margin (top, bottom).
const int kVerticalMargin = 3;

}  // namespace

namespace chromeos {

TextfieldWithMargin::TextfieldWithMargin() {
  CorrectTextfieldFontSize(this);
}

TextfieldWithMargin::TextfieldWithMargin(views::Textfield::StyleFlags style)
    : Textfield(style) {
  CorrectTextfieldFontSize(this);
}

void TextfieldWithMargin::Layout() {
  int margin = GetPreferredSize().height() * kTextMarginRate;
  SetHorizontalMargins(margin, margin);
  SetVerticalMargins(kVerticalMargin, kVerticalMargin);
  views::Textfield::Layout();
}

bool TextfieldWithMargin::OnKeyPressed(const views::KeyEvent& e) {
  if (e.key_code() == ui::VKEY_ESCAPE && !text().empty()) {
    SetText(string16());
    return true;
  }
  return false;
}

}  // namespace chromeos

--- 
+++ 
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 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.
 
@@ -40,7 +40,7 @@
     SetText(string16());
     return true;
   }
-  return false;
+  return views::Textfield::OnKeyPressed(e);
 }
 
 }  // namespace chromeos
Fix to make the behavior of TextfieldWithMargin consistent with Textfield

Add call to views::Textfield::OnKeyPressed in TextfieldWithMargin::OnKeyPressed
Without this call, HandleKeyEvent of controller will not be called by NativeTextfieldViews.

BUG=None
TEST=None

Review URL: http://codereview.chromium.org/7284001

git-svn-id: de016e52bd170d2d4f2344f9bf92d50478b649e0@91090 0039d316-1c4b-4281-b951-d872f2087c98
