#include "ui/views/background.h"
#include "ui/views/controls/focusable_border.h"
#include "ui/views/controls/label.h"
-#include "ui/views/controls/menu/menu_item_view.h"
#include "ui/views/controls/menu/menu_runner.h"
#include "ui/views/controls/native/native_view_host.h"
#include "ui/views/controls/textfield/textfield_controller.h"
#include "ui/views/drag_utils.h"
#include "ui/views/ime/input_method.h"
#include "ui/views/metrics.h"
+#include "ui/views/native_cursor.h"
#include "ui/views/painter.h"
#include "ui/views/views_delegate.h"
#include "ui/views/widget/widget.h"
default:
return kNoCommand;
}
- return kNoCommand;
}
#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
password_reveal_duration_ = ViewsDelegate::views_delegate->
GetDefaultTextfieldObscuredRevealDuration();
}
-
- if (NativeViewHost::kRenderNativeControlFocus)
- focus_painter_ = Painter::CreateDashedFocusPainter();
}
Textfield::~Textfield() {}
return placeholder_text_;
}
+gfx::HorizontalAlignment Textfield::GetHorizontalAlignment() const {
+ return GetRenderText()->horizontal_alignment();
+}
+
+void Textfield::SetHorizontalAlignment(gfx::HorizontalAlignment alignment) {
+ GetRenderText()->SetHorizontalAlignment(alignment);
+}
+
void Textfield::ShowImeIfNeeded() {
- GetInputMethod()->ShowImeIfNeeded();
+ if (enabled() && !read_only())
+ GetInputMethod()->ShowImeIfNeeded();
}
bool Textfield::IsIMEComposing() const {
bool in_selection = GetRenderText()->IsPointInSelection(event.location());
bool drag_event = event.type() == ui::ET_MOUSE_DRAGGED;
bool text_cursor = !initiating_drag_ && (drag_event || !in_selection);
- return text_cursor ? ui::kCursorIBeam : ui::kCursorNull;
+ return text_cursor ? GetNativeIBeamCursor() : gfx::kNullCursor;
}
bool Textfield::OnMousePressed(const ui::MouseEvent& event) {
#endif
}
- touch_selection_controller_.reset();
return true;
}
bool Textfield::OnKeyPressed(const ui::KeyEvent& event) {
bool handled = controller_ && controller_->HandleKeyEvent(this, event);
- touch_selection_controller_.reset();
if (handled)
return true;
event->SetHandled();
} else if (switches::IsTouchDragDropEnabled()) {
initiating_drag_ = true;
- touch_selection_controller_.reset();
+ DestroyTouchSelection();
} else {
if (!touch_selection_controller_)
CreateTouchSelectionControllerAndNotifyIt();
SchedulePaint();
}
-void Textfield::ViewHierarchyChanged(
- const ViewHierarchyChangedDetails& details) {
- if (details.is_add && details.child == this)
- UpdateColorsFromTheme(GetNativeTheme());
-}
-
void Textfield::OnPaint(gfx::Canvas* canvas) {
OnPaintBackground(canvas);
PaintTextAndCursor(canvas);
OnPaintBorder(canvas);
- if (NativeViewHost::kRenderNativeControlFocus)
- Painter::PaintFocusPainter(this, canvas, focus_painter_.get());
}
void Textfield::OnFocus() {
RepaintCursor();
}
- touch_selection_controller_.reset();
+ DestroyTouchSelection();
// Border typically draws focus indicator.
SchedulePaint();
}
void Textfield::OnNativeThemeChanged(const ui::NativeTheme* theme) {
- UpdateColorsFromTheme(theme);
+ gfx::RenderText* render_text = GetRenderText();
+ render_text->SetColor(GetTextColor());
+ UpdateBackgroundColor();
+ render_text->set_cursor_color(GetTextColor());
+ render_text->set_selection_color(theme->GetSystemColor(
+ ui::NativeTheme::kColorId_TextfieldSelectionColor));
+ render_text->set_selection_background_focused_color(theme->GetSystemColor(
+ ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused));
+
}
////////////////////////////////////////////////////////////////////////////////
const gfx::Point& point,
ui::MenuSourceType source_type) {
UpdateContextMenu();
- ignore_result(context_menu_runner_->RunMenuAt(GetWidget(), NULL,
- gfx::Rect(point, gfx::Size()), MenuItemView::TOPLEFT, source_type,
+ ignore_result(context_menu_runner_->RunMenuAt(
+ GetWidget(),
+ NULL,
+ gfx::Rect(point, gfx::Size()),
+ MENU_ANCHOR_TOPLEFT,
+ source_type,
MenuRunner::HAS_MNEMONICS | MenuRunner::CONTEXT_MENU));
}
}
void Textfield::OpenContextMenu(const gfx::Point& anchor) {
- touch_selection_controller_.reset();
+ DestroyTouchSelection();
ShowContextMenu(anchor, ui::MENU_SOURCE_TOUCH_EDIT_MENU);
}
+void Textfield::DestroyTouchSelection() {
+ touch_selection_controller_.reset();
+}
+
////////////////////////////////////////////////////////////////////////////////
// Textfield, ui::SimpleMenuModel::Delegate overrides:
}
void Textfield::ExecuteCommand(int command_id, int event_flags) {
- touch_selection_controller_.reset();
+ DestroyTouchSelection();
if (!IsCommandIdEnabled(command_id))
return;
// IME may want to interact with the native view of [NativeWidget A] rather
// than that of [NativeWidget B]. This is why we need to call
// GetTopLevelWidget() here.
- return GetWidget()->GetTopLevelWidget()->GetNativeView();
+ return GetWidget()->GetTopLevelWidget()->GetNativeWindow();
}
ui::TextInputType Textfield::GetTextInputType() const {
size_t text_index = composition_range.start() + index;
if (composition_range.end() <= text_index)
return false;
- if (!render_text->IsCursorablePosition(text_index)) {
+ if (!render_text->IsValidCursorIndex(text_index)) {
text_index = render_text->IndexOfAdjacentGrapheme(
text_index, gfx::CURSOR_BACKWARD);
}
SchedulePaint();
}
-void Textfield::UpdateColorsFromTheme(const ui::NativeTheme* theme) {
- gfx::RenderText* render_text = GetRenderText();
- render_text->SetColor(GetTextColor());
- UpdateBackgroundColor();
- render_text->set_cursor_color(GetTextColor());
- render_text->set_selection_color(theme->GetSystemColor(
- ui::NativeTheme::kColorId_TextfieldSelectionColor));
- render_text->set_selection_background_focused_color(theme->GetSystemColor(
- ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused));
-}
-
void Textfield::UpdateAfterChange(bool text_changed, bool cursor_changed) {
if (text_changed) {
if (controller_)
cursor_visible_ = true;
RepaintCursor();
if (cursor_repaint_timer_.IsRunning())
- cursor_repaint_timer_.Reset();
+ cursor_repaint_timer_.Reset();
if (!text_changed) {
// TEXT_CHANGED implies SELECTION_CHANGED, so we only need to fire
// this if only the selection changed.