15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef UI_VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_H_ 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define UI_VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_H_ 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <string> 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/basictypes.h" 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/compiler_specific.h" 124c5337722b0050dc1a8f04eaa6e8dcdb69c14334Torne (Richard Coles)#include "base/memory/weak_ptr.h" 135e3f23d412006dc4db4e659864679f29341e113fTorne (Richard Coles)#include "base/strings/string16.h" 14eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "base/time/time.h" 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "build/build_config.h" 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "third_party/skia/include/core/SkColor.h" 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/base/ime/text_input_type.h" 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/base/keycodes/keyboard_codes.h" 19a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "ui/gfx/font_list.h" 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/native_widget_types.h" 212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/gfx/text_constants.h" 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/controls/textfield/native_textfield_wrapper.h" 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/view.h" 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if !defined(OS_LINUX) 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/logging.h" 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace gfx { 302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class ImageSkia; 312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace ui { 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class Range; 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class TextInputClient; 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace ui 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace views { 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class ImageView; 412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class TextfieldController; 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This class implements a View that wraps a native text (edit) field. 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class VIEWS_EXPORT Textfield : public View { 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 47868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // The textfield's class name. 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static const char kViewClassName[]; 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) enum StyleFlags { 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) STYLE_DEFAULT = 0, 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) STYLE_OBSCURED = 1 << 0, 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) STYLE_LOWERCASE = 1 << 1 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }; 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns true if the build or commandline dictates NativeTextfieldViews use. 575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static bool IsViewsTextfieldEnabled(); 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Textfield(); 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) explicit Textfield(StyleFlags style); 615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual ~Textfield(); 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // TextfieldController accessors 645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SetController(TextfieldController* controller); 655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) TextfieldController* GetController() const; 665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Gets/Sets whether or not the Textfield is read-only. 685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool read_only() const { return read_only_; } 695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SetReadOnly(bool read_only); 705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Gets/sets the STYLE_OBSCURED bit, controlling whether characters in this 725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Textfield are displayed as asterisks/bullets. 735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool IsObscured() const; 745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SetObscured(bool obscured); 755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 76868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Gets/sets the duration to reveal the last typed char when the obscured bit 77868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // is set. A duration of zero effectively disables the feature. Other values 78868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // cause the last typed char to be shown for the defined duration. Note this 79868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // only works with NativeTextfieldViews. 80868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) const base::TimeDelta& obscured_reveal_duration() const { 81868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) return obscured_reveal_duration_; 82868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) } 83868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) void set_obscured_reveal_duration(const base::TimeDelta& duration) { 84868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) obscured_reveal_duration_ = duration; 85868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) } 86868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Gets/Sets the input type of this textfield. 885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ui::TextInputType GetTextInputType() const; 895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SetTextInputType(ui::TextInputType type); 905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Gets/Sets the text currently displayed in the Textfield. 925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const string16& text() const { return text_; } 935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Sets the text currently displayed in the Textfield. This doesn't 955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // change the cursor position if the current cursor is within the 965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // new text's range, or moves the cursor to the end if the cursor is 975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // out of the new text's range. 985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SetText(const string16& text); 995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Appends the given string to the previously-existing text in the field. 1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void AppendText(const string16& text); 1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1037d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // Inserts |text| at the current cursor position, replacing any selected text. 1047d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) void InsertOrReplaceText(const string16& text); 1052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns the text direction. 1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::i18n::TextDirection GetTextDirection() const; 1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns the text that is currently selected. 1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) string16 GetSelectedText() const; 1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Select the entire text range. If |reversed| is true, the range will end at 1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the logical beginning of the text; this generally shows the leading portion 1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // of text that overflows its display area. 1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SelectAll(bool reversed); 1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Clears the selection within the edit field and sets the caret to the end. 1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void ClearSelection() const; 1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Checks if there is any selected text. 1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool HasSelection() const; 1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Accessor for |style_|. 1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) StyleFlags style() const { return style_; } 1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Gets/Sets the text color to be used when painting the Textfield. 1272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Call |UseDefaultTextColor| to restore the default system color. 1282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) SkColor GetTextColor() const; 1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SetTextColor(SkColor color); 1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void UseDefaultTextColor(); 1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Gets/Sets the background color to be used when painting the Textfield. 1332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Call |UseDefaultBackgroundColor| to restore the default system color. 1342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) SkColor GetBackgroundColor() const; 1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SetBackgroundColor(SkColor color); 1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void UseDefaultBackgroundColor(); 1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Gets/Sets whether or not the cursor is enabled. 1392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool GetCursorEnabled() const; 1402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void SetCursorEnabled(bool enabled); 1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 142a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) // Gets/Sets the fonts used when rendering the text within the Textfield. 143a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) const gfx::FontList& font_list() const { return font_list_; } 144a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) void SetFontList(const gfx::FontList& font_list); 145a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) const gfx::Font& GetPrimaryFont() const; 1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SetFont(const gfx::Font& font); 1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Sets the left and right margin (in pixels) within the text box. On Windows 1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // this is accomplished by packing the left and right margin into a single 1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 32 bit number, so the left and right margins are effectively 16 bits. 1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SetHorizontalMargins(int left, int right); 1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Sets the top and bottom margins (in pixels) within the textfield. 1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // NOTE: in most cases height could be changed instead. 1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SetVerticalMargins(int top, int bottom); 1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 15790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Set the text vertical alignment. Text is vertically centered by default. 15890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) gfx::VerticalAlignment vertical_alignment() const { 15990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) return vertical_alignment_; 16090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } 16190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) void SetVerticalAlignment(gfx::VerticalAlignment alignment); 16290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 1635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Sets the default width of the text control. See default_width_in_chars_. 1645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void set_default_width_in_chars(int default_width) { 1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) default_width_in_chars_ = default_width; 1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Removes the border from the edit box, giving it a 2D look. 1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool draw_border() const { return draw_border_; } 1705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void RemoveBorder(); 1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Sets the text to display when empty. 1735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void set_placeholder_text(const string16& text) { 1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) placeholder_text_ = text; 1755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if !defined(OS_LINUX) 1765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NOTIMPLEMENTED(); 1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif 1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const string16& placeholder_text() const { 1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return placeholder_text_; 1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SkColor placeholder_text_color() const { return placeholder_text_color_; } 1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void set_placeholder_text_color(SkColor color) { 1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) placeholder_text_color_ = color; 1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Getter for the horizontal margins that were set. Returns false if 1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // horizontal margins weren't set. 1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool GetHorizontalMargins(int* left, int* right); 1915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Getter for the vertical margins that were set. Returns false if vertical 1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // margins weren't set. 1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool GetVerticalMargins(int* top, int* bottom); 1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Updates all properties on the textfield. This is invoked internally. 1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Users of Textfield never need to invoke this directly. 1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void UpdateAllProperties(); 1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Invoked by the edit control when the value changes. This method set 2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the text_ member variable to the value contained in edit control. 2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This is important because the edit control can be replaced if it has 2035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // been deleted during a window close. 2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SyncText(); 2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns whether or not an IME is composing text. 2075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool IsIMEComposing() const; 2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Gets the selected range. This is views-implementation only and 2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // has to be called after the wrapper is created. 2112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // TODO(msw): Return a const reference when NativeTextfieldWin is gone. 2122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ui::Range GetSelectedRange() const; 2135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Selects the text given by |range|. This is views-implementation only and 2155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // has to be called after the wrapper is created. 2165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SelectRange(const ui::Range& range); 2175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Gets the selection model. This is views-implementation only and 2195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // has to be called after the wrapper is created. 2202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // TODO(msw): Return a const reference when NativeTextfieldWin is gone. 2212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::SelectionModel GetSelectionModel() const; 2225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Selects the text given by |sel|. This is views-implementation only and 2245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // has to be called after the wrapper is created. 2255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SelectSelectionModel(const gfx::SelectionModel& sel); 2265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns the current cursor position. This is views-implementation 2285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // only and has to be called after the wrapper is created. 2295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) size_t GetCursorPosition() const; 2305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Set the text color over the entire text or a logical character range. 2322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Empty and invalid ranges are ignored. This is views-implementation only and 2335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // has to be called after the wrapper is created. 2342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void SetColor(SkColor value); 2352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void ApplyColor(SkColor value, const ui::Range& range); 2365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Set various text styles over the entire text or a logical character range. 2382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // The respective |style| is applied if |value| is true, or removed if false. 2392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Empty and invalid ranges are ignored. This is views-implementation only and 2402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // has to be called after the wrapper is created. 2412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void SetStyle(gfx::TextStyle style, bool value); 2422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void ApplyStyle(gfx::TextStyle style, bool value, const ui::Range& range); 2435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Clears Edit history. 2455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void ClearEditHistory(); 2465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Set the accessible name of the text field. 2485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SetAccessibleName(const string16& name); 2495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Performs the action associated with the specified command id. 2512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void ExecuteCommand(int command_id); 2522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Provided only for testing: 2545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::NativeView GetTestingHandle() const { 2555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return native_wrapper_ ? native_wrapper_->GetTestingHandle() : NULL; 2565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NativeTextfieldWrapper* GetNativeWrapperForTesting() const { 2585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return native_wrapper_; 2595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 261c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Returns whether there is a drag operation originating from the textfield. 262c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) bool HasTextBeingDragged(); 263c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 2645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Overridden from View: 2655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void Layout() OVERRIDE; 2662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual int GetBaseline() const OVERRIDE; 2675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual gfx::Size GetPreferredSize() OVERRIDE; 2685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void AboutToRequestFocusFromTabTraversal(bool reverse) OVERRIDE; 2695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual bool SkipDefaultKeyEventProcessing(const ui::KeyEvent& e) OVERRIDE; 2705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void OnEnabledChanged() OVERRIDE; 2715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void OnPaintFocusBorder(gfx::Canvas* canvas) OVERRIDE; 2725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual bool OnKeyPressed(const ui::KeyEvent& e) OVERRIDE; 2735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual bool OnKeyReleased(const ui::KeyEvent& e) OVERRIDE; 2745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual bool OnMouseDragged(const ui::MouseEvent& e) OVERRIDE; 2755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void OnFocus() OVERRIDE; 2765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void OnBlur() OVERRIDE; 2775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; 2785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual ui::TextInputClient* GetTextInputClient() OVERRIDE; 2795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected: 281a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) virtual void ViewHierarchyChanged( 282a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) const ViewHierarchyChangedDetails& details) OVERRIDE; 283b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) virtual const char* GetClassName() const OVERRIDE; 2845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The object that actually implements the native text field. 2865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NativeTextfieldWrapper* native_wrapper_; 2875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private: 289eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Returns the insets to the rectangle where text is actually painted. 290eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch gfx::Insets GetTextInsets() const; 291eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 2924c5337722b0050dc1a8f04eaa6e8dcdb69c14334Torne (Richard Coles) // Handles a request to change the value of this text field from software 2934c5337722b0050dc1a8f04eaa6e8dcdb69c14334Torne (Richard Coles) // using an accessibility API (typically automation software, screen readers 2944c5337722b0050dc1a8f04eaa6e8dcdb69c14334Torne (Richard Coles) // don't normally use this). Sets the value and clears the selection. 2954c5337722b0050dc1a8f04eaa6e8dcdb69c14334Torne (Richard Coles) void AccessibilitySetValue(const string16& new_value); 2964c5337722b0050dc1a8f04eaa6e8dcdb69c14334Torne (Richard Coles) 2975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This is the current listener for events from this Textfield. 2985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) TextfieldController* controller_; 2995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The mask of style options for this Textfield. 3015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) StyleFlags style_; 3025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 303a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) // The fonts used to render the text in the Textfield. 304a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) gfx::FontList font_list_; 3055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The text displayed in the Textfield. 3075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) string16 text_; 3085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // True if this Textfield cannot accept input and is read-only. 3105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool read_only_; 3115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The default number of average characters for the width of this text field. 3135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This will be reported as the "desired size". Defaults to 0. 3145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int default_width_in_chars_; 3155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Whether the border is drawn. 3175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool draw_border_; 3185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Text color. Only used if |use_default_text_color_| is false. 3205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SkColor text_color_; 3215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Should we use the system text color instead of |text_color_|? 3235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool use_default_text_color_; 3245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Background color. Only used if |use_default_background_color_| is false. 3265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SkColor background_color_; 3275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Should we use the system background color instead of |background_color_|? 3295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool use_default_background_color_; 3305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Holds inner textfield margins. 3325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Insets margins_; 3335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Holds whether margins were set. 3355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool horizontal_margins_were_set_; 3365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool vertical_margins_were_set_; 3375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 33890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // The vertical alignment of text in the Textfield. 33990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) gfx::VerticalAlignment vertical_alignment_; 34090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 3415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Text to display when empty. 3425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) string16 placeholder_text_; 3435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Placeholder text color. 3455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SkColor placeholder_text_color_; 3465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The accessible name of the text field. 3485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) string16 accessible_name_; 3495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The input type of this text field. 3515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ui::TextInputType text_input_type_; 3525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 353868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // The duration to reveal the last typed char for obscured textfields. 354868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) base::TimeDelta obscured_reveal_duration_; 355868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 3564c5337722b0050dc1a8f04eaa6e8dcdb69c14334Torne (Richard Coles) // Used to bind callback functions to this object. 3574c5337722b0050dc1a8f04eaa6e8dcdb69c14334Torne (Richard Coles) base::WeakPtrFactory<Textfield> weak_ptr_factory_; 3584c5337722b0050dc1a8f04eaa6e8dcdb69c14334Torne (Richard Coles) 3595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(Textfield); 3605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 3615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace views 3635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif // UI_VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_H_ 365