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

Unified Diff: chrome/browser/ui/views/omnibox/omnibox_view_views.cc

Issue 271013002: Compute minimum widths for the toolbar components. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/views/omnibox/omnibox_view_views.cc
diff --git a/chrome/browser/ui/views/omnibox/omnibox_view_views.cc b/chrome/browser/ui/views/omnibox/omnibox_view_views.cc
index 088bab5048d99f63cb04e88d36f0639d81db7063..f4e09db3f0536718dac74a9a54c7bd71c0883fb2 100644
--- a/chrome/browser/ui/views/omnibox/omnibox_view_views.cc
+++ b/chrome/browser/ui/views/omnibox/omnibox_view_views.cc
@@ -60,8 +60,11 @@
#include "chrome/browser/browser_process.h"
#endif
+
namespace {
+// OmniboxState ---------------------------------------------------------------
+
// Stores omnibox state for each tab.
struct OmniboxState : public base::SupportsUserData::Data {
static const char kKey[];
@@ -92,7 +95,11 @@ OmniboxState::OmniboxState(const OmniboxEditModel::State& model_state,
saved_selection_for_focus_change(saved_selection_for_focus_change) {
}
-OmniboxState::~OmniboxState() {}
+OmniboxState::~OmniboxState() {
+}
+
+
+// Helpers --------------------------------------------------------------------
// We'd like to set the text input type to TEXT_INPUT_TYPE_URL, because this
// triggers URL-specific layout in software keyboards, e.g. adding top-level "/"
@@ -117,6 +124,9 @@ ui::TextInputType DetermineTextInputType() {
} // namespace
+
+// OmniboxViewViews -----------------------------------------------------------
+
// static
const char OmniboxViewViews::kViewClassName[] = "OmniboxViewViews";
@@ -152,9 +162,6 @@ OmniboxViewViews::~OmniboxViewViews() {
popup_view_.reset();
}
-////////////////////////////////////////////////////////////////////////////////
-// OmniboxViewViews public:
-
void OmniboxViewViews::Init() {
set_controller(this);
SetTextInputType(DetermineTextInputType());
@@ -180,9 +187,6 @@ void OmniboxViewViews::FadeIn() {
fade_in_animation_->Show();
}
-////////////////////////////////////////////////////////////////////////////////
-// OmniboxViewViews, public OmniboxView implementation:
-
void OmniboxViewViews::SaveStateToTab(content::WebContents* tab) {
DCHECK(tab);
@@ -315,6 +319,20 @@ bool OmniboxViewViews::IsImeComposing() const {
return IsIMEComposing();
}
+gfx::Size OmniboxViewViews::GetMinimumSize() {
+ const int kMinCharacters = 10;
+ return gfx::Size(
+ GetFontList().GetExpectedTextWidth(kMinCharacters) + GetInsets.width(),
+ GetPreferredSize().height());
+}
+
+void OmniboxViewViews::OnNativeThemeChanged(const ui::NativeTheme* theme) {
+ views::Textfield::OnNativeThemeChanged(theme);
+ SetBackgroundColor(location_bar_view_->GetColor(
+ ToolbarModel::NONE, LocationBarView::BACKGROUND));
+ EmphasizeURLComponents();
+}
+
void OmniboxViewViews::ExecuteCommand(int command_id, int event_flags) {
switch (command_id) {
// These commands don't invoke the popup via OnBefore/AfterPossibleChange().
@@ -345,53 +363,6 @@ void OmniboxViewViews::ExecuteCommand(int command_id, int event_flags) {
}
}
-////////////////////////////////////////////////////////////////////////////////
-// OmniboxViewViews, private:
-
-int OmniboxViewViews::GetOmniboxTextLength() const {
- // TODO(oshima): Support IME.
- return static_cast<int>(text().length());
-}
-
-void OmniboxViewViews::EmphasizeURLComponents() {
- // See whether the contents are a URL with a non-empty host portion, which we
- // should emphasize. To check for a URL, rather than using the type returned
- // by Parse(), ask the model, which will check the desired page transition for
- // this input. This can tell us whether an UNKNOWN input string is going to
- // be treated as a search or a navigation, and is the same method the Paste
- // And Go system uses.
- url::Component scheme, host;
- AutocompleteInput::ParseForEmphasizeComponents(text(), &scheme, &host);
- bool grey_out_url = text().substr(scheme.begin, scheme.len) ==
- base::UTF8ToUTF16(extensions::kExtensionScheme);
- bool grey_base = model()->CurrentTextIsURL() &&
- (host.is_nonempty() || grey_out_url);
- SetColor(location_bar_view_->GetColor(
- security_level_,
- grey_base ? LocationBarView::DEEMPHASIZED_TEXT : LocationBarView::TEXT));
- if (grey_base && !grey_out_url) {
- ApplyColor(
- location_bar_view_->GetColor(security_level_, LocationBarView::TEXT),
- gfx::Range(host.begin, host.end()));
- }
-
- // Emphasize the scheme for security UI display purposes (if necessary).
- // Note that we check CurrentTextIsURL() because if we're replacing search
- // URLs with search terms, we may have a non-URL even when the user is not
- // editing; and in some cases, e.g. for "site:foo.com" searches, the parser
- // may have incorrectly identified a qualifier as a scheme.
- SetStyle(gfx::DIAGONAL_STRIKE, false);
- if (!model()->user_input_in_progress() && model()->CurrentTextIsURL() &&
- scheme.is_nonempty() && (security_level_ != ToolbarModel::NONE)) {
- SkColor security_color = location_bar_view_->GetColor(
- security_level_, LocationBarView::SECURITY_TEXT);
- const bool strike = (security_level_ == ToolbarModel::SECURITY_ERROR);
- const gfx::Range scheme_range(scheme.begin, scheme.end());
- ApplyColor(security_color, scheme_range);
- ApplyStyle(gfx::DIAGONAL_STRIKE, strike, scheme_range);
- }
-}
-
void OmniboxViewViews::SetTextAndSelectedRange(const base::string16& text,
Greg Billock 2014/05/13 16:08:15 These are all just re-ordered, right?
Peter Kasting 2014/05/13 20:50:14 Yes. The only functional change is the addition o
const gfx::Range& range) {
SetText(text);
@@ -438,19 +409,6 @@ bool OmniboxViewViews::HandleEarlyTabActions(const ui::KeyEvent& event) {
return false;
}
-////////////////////////////////////////////////////////////////////////////////
-// OmniboxViewViews, private View implementation:
-
-void OmniboxViewViews::OnNativeThemeChanged(const ui::NativeTheme* theme) {
- views::Textfield::OnNativeThemeChanged(theme);
- SetBackgroundColor(location_bar_view_->GetColor(
- ToolbarModel::NONE, LocationBarView::BACKGROUND));
- EmphasizeURLComponents();
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// OmniboxViewViews, private OmniboxView implementation:
-
void OmniboxViewViews::SetWindowTextAndCaretPos(const base::string16& text,
size_t caret_pos,
bool update_popup,
@@ -613,16 +571,55 @@ void OmniboxViewViews::OnMatchOpened(const AutocompleteMatch& match,
profile, web_contents, match);
}
-bool OmniboxViewViews::IsCommandIdEnabled(int command_id) const {
- if (command_id == IDS_APP_PASTE)
- return !read_only() && !GetClipboardText().empty();
- if (command_id == IDS_PASTE_AND_GO)
- return !read_only() && model()->CanPasteAndGo(GetClipboardText());
- if (command_id == IDS_SHOW_URL)
- return controller()->GetToolbarModel()->WouldReplaceURL();
- return command_id == IDS_MOVE_DOWN || command_id == IDS_MOVE_UP ||
- Textfield::IsCommandIdEnabled(command_id) ||
- command_updater()->IsCommandEnabled(command_id);
+int OmniboxViewViews::GetOmniboxTextLength() const {
+ // TODO(oshima): Support IME.
+ return static_cast<int>(text().length());
+}
+
+void OmniboxViewViews::EmphasizeURLComponents() {
+ // See whether the contents are a URL with a non-empty host portion, which we
+ // should emphasize. To check for a URL, rather than using the type returned
+ // by Parse(), ask the model, which will check the desired page transition for
+ // this input. This can tell us whether an UNKNOWN input string is going to
+ // be treated as a search or a navigation, and is the same method the Paste
+ // And Go system uses.
+ url::Component scheme, host;
+ AutocompleteInput::ParseForEmphasizeComponents(text(), &scheme, &host);
+ bool grey_out_url = text().substr(scheme.begin, scheme.len) ==
+ base::UTF8ToUTF16(extensions::kExtensionScheme);
+ bool grey_base = model()->CurrentTextIsURL() &&
+ (host.is_nonempty() || grey_out_url);
+ SetColor(location_bar_view_->GetColor(
+ security_level_,
+ grey_base ? LocationBarView::DEEMPHASIZED_TEXT : LocationBarView::TEXT));
+ if (grey_base && !grey_out_url) {
+ ApplyColor(
+ location_bar_view_->GetColor(security_level_, LocationBarView::TEXT),
+ gfx::Range(host.begin, host.end()));
+ }
+
+ // Emphasize the scheme for security UI display purposes (if necessary).
+ // Note that we check CurrentTextIsURL() because if we're replacing search
+ // URLs with search terms, we may have a non-URL even when the user is not
+ // editing; and in some cases, e.g. for "site:foo.com" searches, the parser
+ // may have incorrectly identified a qualifier as a scheme.
+ SetStyle(gfx::DIAGONAL_STRIKE, false);
+ if (!model()->user_input_in_progress() && model()->CurrentTextIsURL() &&
+ scheme.is_nonempty() && (security_level_ != ToolbarModel::NONE)) {
+ SkColor security_color = location_bar_view_->GetColor(
+ security_level_, LocationBarView::SECURITY_TEXT);
+ const bool strike = (security_level_ == ToolbarModel::SECURITY_ERROR);
+ const gfx::Range scheme_range(scheme.begin, scheme.end());
+ ApplyColor(security_color, scheme_range);
+ ApplyStyle(gfx::DIAGONAL_STRIKE, strike, scheme_range);
+ }
+}
+
+bool OmniboxViewViews::OnKeyReleased(const ui::KeyEvent& event) {
+ // The omnibox contents may change while the control key is pressed.
+ if (event.key_code() == ui::VKEY_CONTROL)
+ model()->OnControlKeyChanged(false);
+ return views::Textfield::OnKeyReleased(event);
}
bool OmniboxViewViews::IsItemForCommandIdDynamic(int command_id) const {
@@ -636,24 +633,10 @@ base::string16 OmniboxViewViews::GetLabelForCommandId(int command_id) const {
IDS_PASTE_AND_SEARCH : IDS_PASTE_AND_GO);
}
-////////////////////////////////////////////////////////////////////////////////
-// OmniboxViewViews, private views::Textfield implementation:
-
const char* OmniboxViewViews::GetClassName() const {
return kViewClassName;
}
-void OmniboxViewViews::OnPaint(gfx::Canvas* canvas) {
- if (fade_in_animation_->is_animating()) {
- canvas->SaveLayerAlpha(static_cast<uint8>(
- fade_in_animation_->CurrentValueBetween(0, 255)));
- views::Textfield::OnPaint(canvas);
- canvas->Restore();
- } else {
- views::Textfield::OnPaint(canvas);
- }
-}
-
bool OmniboxViewViews::OnMousePressed(const ui::MouseEvent& event) {
select_all_on_mouse_release_ =
(event.IsOnlyLeftMouseButton() || event.IsOnlyRightMouseButton()) &&
@@ -766,13 +749,6 @@ bool OmniboxViewViews::OnKeyPressed(const ui::KeyEvent& event) {
return views::Textfield::OnKeyPressed(event) || HandleEarlyTabActions(event);
}
-bool OmniboxViewViews::OnKeyReleased(const ui::KeyEvent& event) {
- // The omnibox contents may change while the control key is pressed.
- if (event.key_code() == ui::VKEY_CONTROL)
- model()->OnControlKeyChanged(false);
- return views::Textfield::OnKeyReleased(event);
-}
-
void OmniboxViewViews::OnGestureEvent(ui::GestureEvent* event) {
if (!HasFocus() && event->type() == ui::ET_GESTURE_TAP_DOWN) {
select_all_on_gesture_tap_ = true;
@@ -820,6 +796,17 @@ void OmniboxViewViews::GetAccessibleState(ui::AXViewState* state) {
state->role = ui::AX_ROLE_TEXT_FIELD;
}
+void OmniboxViewViews::OnPaint(gfx::Canvas* canvas) {
+ if (fade_in_animation_->is_animating()) {
+ canvas->SaveLayerAlpha(static_cast<uint8>(
+ fade_in_animation_->CurrentValueBetween(0, 255)));
+ views::Textfield::OnPaint(canvas);
+ canvas->Restore();
+ } else {
+ views::Textfield::OnPaint(canvas);
+ }
+}
+
void OmniboxViewViews::OnFocus() {
views::Textfield::OnFocus();
// TODO(oshima): Get control key state.
@@ -862,13 +849,22 @@ void OmniboxViewViews::OnBlur() {
SelectRange(gfx::Range(0));
}
+bool OmniboxViewViews::IsCommandIdEnabled(int command_id) const {
+ if (command_id == IDS_APP_PASTE)
+ return !read_only() && !GetClipboardText().empty();
+ if (command_id == IDS_PASTE_AND_GO)
+ return !read_only() && model()->CanPasteAndGo(GetClipboardText());
+ if (command_id == IDS_SHOW_URL)
+ return controller()->GetToolbarModel()->WouldReplaceURL();
+ return command_id == IDS_MOVE_DOWN || command_id == IDS_MOVE_UP ||
+ Textfield::IsCommandIdEnabled(command_id) ||
+ command_updater()->IsCommandEnabled(command_id);
+}
+
base::string16 OmniboxViewViews::GetSelectionClipboardText() const {
return SanitizeTextForPaste(Textfield::GetSelectionClipboardText());
}
-////////////////////////////////////////////////////////////////////////////////
-// OmniboxViewViews, private gfx::AnimationDelegate implementation:
-
void OmniboxViewViews::AnimationProgressed(const gfx::Animation* animation) {
SchedulePaint();
}
@@ -877,11 +873,6 @@ void OmniboxViewViews::AnimationEnded(const gfx::Animation* animation) {
fade_in_animation_->Reset();
}
-////////////////////////////////////////////////////////////////////////////////
-// OmniboxViewViews,
-// chromeos::input_method::InputMethodManager::CandidateWindowObserver
-// private implementation:
-
#if defined(OS_CHROMEOS)
void OmniboxViewViews::CandidateWindowOpened(
chromeos::input_method::InputMethodManager* manager) {
@@ -894,9 +885,6 @@ void OmniboxViewViews::CandidateWindowClosed(
}
#endif
-////////////////////////////////////////////////////////////////////////////////
-// OmniboxViewViews, private views::TextfieldController implementation:
-
void OmniboxViewViews::ContentsChanged(views::Textfield* sender,
const base::string16& new_contents) {
}
« no previous file with comments | « chrome/browser/ui/views/omnibox/omnibox_view_views.h ('k') | chrome/browser/ui/views/toolbar/browser_actions_container.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698