Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(22)

Side by Side Diff: views/controls/textfield/native_textfield_views.cc

Issue 7265011: RenderText API Outline. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add some placeholder functionality on Windows. Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "views/controls/textfield/native_textfield_views.h" 5 #include "views/controls/textfield/native_textfield_views.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/message_loop.h" 11 #include "base/message_loop.h"
12 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
13 #include "grit/app_strings.h" 13 #include "grit/app_strings.h"
14 #include "ui/base/clipboard/clipboard.h" 14 #include "ui/base/clipboard/clipboard.h"
15 #include "ui/base/dragdrop/drag_drop_types.h" 15 #include "ui/base/dragdrop/drag_drop_types.h"
16 #include "ui/base/range/range.h" 16 #include "ui/base/range/range.h"
17 #include "ui/gfx/canvas.h" 17 #include "ui/gfx/canvas.h"
18 #include "ui/gfx/insets.h" 18 #include "ui/gfx/insets.h"
19 #include "ui/gfx/render_text.h"
19 #include "views/background.h" 20 #include "views/background.h"
20 #include "views/border.h" 21 #include "views/border.h"
21 #include "views/controls/focusable_border.h" 22 #include "views/controls/focusable_border.h"
22 #include "views/controls/menu/menu_item_view.h" 23 #include "views/controls/menu/menu_item_view.h"
23 #include "views/controls/menu/menu_model_adapter.h" 24 #include "views/controls/menu/menu_model_adapter.h"
24 #include "views/controls/textfield/text_style.h" 25 #include "views/controls/textfield/text_style.h"
25 #include "views/controls/textfield/textfield.h" 26 #include "views/controls/textfield/textfield.h"
26 #include "views/controls/textfield/textfield_controller.h" 27 #include "views/controls/textfield/textfield_controller.h"
27 #include "views/controls/textfield/textfield_views_model.h" 28 #include "views/controls/textfield/textfield_views_model.h"
28 #include "views/events/event.h" 29 #include "views/events/event.h"
(...skipping 783 matching lines...) Expand 10 before | Expand all | Expand 10 after
812 OnCaretBoundsChanged(); 813 OnCaretBoundsChanged();
813 } 814 }
814 815
815 void NativeTextfieldViews::PaintTextAndCursor(gfx::Canvas* canvas) { 816 void NativeTextfieldViews::PaintTextAndCursor(gfx::Canvas* canvas) {
816 gfx::Insets insets = GetInsets(); 817 gfx::Insets insets = GetInsets();
817 818
818 canvas->Save(); 819 canvas->Save();
819 canvas->ClipRectInt(insets.left(), insets.top(), 820 canvas->ClipRectInt(insets.left(), insets.top(),
820 width() - insets.width(), height() - insets.height()); 821 width() - insets.width(), height() - insets.height());
821 822
823 // TODO(msw): Fix... integrate, etc...
824 int x = text_offset_ + insets.left();
825 int y = insets.top();
826 int w = GetFont().GetStringWidth(model_->text());
827 int h = height() - insets.height();
828 gfx::Rect display_bounds = gfx::Rect(x, y, w, h);
829 gfx::RenderText* render_text = gfx::RenderText::CreateRenderText(
830 model_->text(), GetFont(), GetTextColor(), display_bounds, 0);
831
832 canvas->DrawStringInt(*render_text);
833
834 /* TODO(msw): Fix... integrate, etc...
822 // TODO(oshima): bidi support 835 // TODO(oshima): bidi support
823 // TODO(varunjain): re-implement this so only that dirty text is painted. 836 // TODO(varunjain): re-implement this so only that dirty text is painted.
824 TextfieldViewsModel::TextFragments fragments; 837 TextfieldViewsModel::TextFragments fragments;
825 model_->GetFragments(&fragments); 838 model_->GetFragments(&fragments);
826 int x_offset = text_offset_ + insets.left(); 839 int x_offset = text_offset_ + insets.left();
827 int y = insets.top(); 840 int y = insets.top();
828 int text_height = height() - insets.height(); 841 int text_height = height() - insets.height();
829 SkColor selection_color = 842 SkColor selection_color =
830 textfield_->HasFocus() ? 843 textfield_->HasFocus() ?
831 kFocusedSelectionColor : kUnfocusedSelectionColor; 844 kFocusedSelectionColor : kUnfocusedSelectionColor;
(...skipping 24 matching lines...) Expand all
856 canvas->Restore(); 869 canvas->Restore();
857 870
858 // Paint cursor. Replace cursor is drawn as rectangle for now. 871 // Paint cursor. Replace cursor is drawn as rectangle for now.
859 if (textfield_->IsEnabled() && (is_drop_cursor_visible_ || 872 if (textfield_->IsEnabled() && (is_drop_cursor_visible_ ||
860 (is_cursor_visible_ && !model_->HasSelection()))) 873 (is_cursor_visible_ && !model_->HasSelection())))
861 canvas->DrawRectInt(kCursorColor, 874 canvas->DrawRectInt(kCursorColor,
862 cursor_bounds_.x(), 875 cursor_bounds_.x(),
863 cursor_bounds_.y(), 876 cursor_bounds_.y(),
864 cursor_bounds_.width(), 877 cursor_bounds_.width(),
865 cursor_bounds_.height()); 878 cursor_bounds_.height());
879 */
866 } 880 }
867 881
868 bool NativeTextfieldViews::HandleKeyEvent(const KeyEvent& key_event) { 882 bool NativeTextfieldViews::HandleKeyEvent(const KeyEvent& key_event) {
869 // TODO(oshima): Refactor and consolidate with ExecuteCommand. 883 // TODO(oshima): Refactor and consolidate with ExecuteCommand.
870 if (key_event.type() == ui::ET_KEY_PRESSED) { 884 if (key_event.type() == ui::ET_KEY_PRESSED) {
871 ui::KeyboardCode key_code = key_event.key_code(); 885 ui::KeyboardCode key_code = key_event.key_code();
872 // TODO(oshima): shift-tab does not work. Figure out why and fix. 886 // TODO(oshima): shift-tab does not work. Figure out why and fix.
873 if (key_code == ui::VKEY_TAB) 887 if (key_code == ui::VKEY_TAB)
874 return false; 888 return false;
875 889
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
1109 // Filter out all control characters, including tab and new line characters, 1123 // Filter out all control characters, including tab and new line characters,
1110 // and all characters with Alt modifier. But we need to allow characters with 1124 // and all characters with Alt modifier. But we need to allow characters with
1111 // AltGr modifier. 1125 // AltGr modifier.
1112 // On Windows AltGr is represented by Alt+Ctrl, and on Linux it's a different 1126 // On Windows AltGr is represented by Alt+Ctrl, and on Linux it's a different
1113 // flag that we don't care about. 1127 // flag that we don't care about.
1114 return ((ch >= 0x20 && ch < 0x7F) || ch > 0x9F) && 1128 return ((ch >= 0x20 && ch < 0x7F) || ch > 0x9F) &&
1115 (flags & ~(ui::EF_SHIFT_DOWN | ui::EF_CAPS_LOCK_DOWN)) != ui::EF_ALT_DOWN; 1129 (flags & ~(ui::EF_SHIFT_DOWN | ui::EF_CAPS_LOCK_DOWN)) != ui::EF_ALT_DOWN;
1116 } 1130 }
1117 1131
1118 } // namespace views 1132 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698