| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "chrome/browser/autocomplete/autocomplete_edit_view_gtk.h" | 5 #include "chrome/browser/autocomplete/autocomplete_edit_view_gtk.h" |
| 6 | 6 |
| 7 #include <gtk/gtk.h> | 7 #include <gtk/gtk.h> |
| 8 #include <gdk/gdkkeysyms.h> | 8 #include <gdk/gdkkeysyms.h> |
| 9 | 9 |
| 10 #include "base/gfx/gtk_util.h" | 10 #include "base/gfx/gtk_util.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
| 13 #include "chrome/browser/autocomplete/autocomplete_edit.h" | 13 #include "chrome/browser/autocomplete/autocomplete_edit.h" |
| 14 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" | 14 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" |
| 15 #include "chrome/browser/autocomplete/autocomplete_popup_view_gtk.h" | 15 #include "chrome/browser/autocomplete/autocomplete_popup_view_gtk.h" |
| 16 #include "chrome/browser/tab_contents/tab_contents.h" | 16 #include "chrome/browser/tab_contents/tab_contents.h" |
| 17 #include "chrome/browser/toolbar_model.h" | 17 #include "chrome/browser/toolbar_model.h" |
| 18 #include "chrome/common/notification_service.h" | 18 #include "chrome/common/notification_service.h" |
| 19 #include "googleurl/src/gurl.h" | 19 #include "googleurl/src/gurl.h" |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 const char kTextBaseColor[] = "#808080"; | 23 const char kTextBaseColor[] = "#808080"; |
| 24 const char kSecureSchemeColor[] = "#009614"; | 24 const char kSecureSchemeColor[] = "#009614"; |
| 25 const char kInsecureSchemeColor[] = "#009614"; | 25 const char kInsecureSchemeColor[] = "#c80000"; |
| 26 const GdkColor kSecureBackgroundColor = GDK_COLOR_RGB(0xff, 0xf5, 0xc3); | 26 |
| 27 const GdkColor kInsecureBackgroundColor = GDK_COLOR_RGB(0xff, 0xff, 0xff); | 27 const GdkColor kBackgroundColorByLevel[] = { |
| 28 GDK_COLOR_RGB(255, 245, 195), // SecurityLevel SECURE: Yellow. |
| 29 GDK_COLOR_RGB(255, 255, 255), // SecurityLevel NORMAL: White. |
| 30 GDK_COLOR_RGB(255, 255, 255), // SecurityLevel INSECURE: White. |
| 31 }; |
| 28 | 32 |
| 29 } // namespace | 33 } // namespace |
| 30 | 34 |
| 31 AutocompleteEditViewGtk::AutocompleteEditViewGtk( | 35 AutocompleteEditViewGtk::AutocompleteEditViewGtk( |
| 32 AutocompleteEditController* controller, | 36 AutocompleteEditController* controller, |
| 33 ToolbarModel* toolbar_model, | 37 ToolbarModel* toolbar_model, |
| 34 Profile* profile, | 38 Profile* profile, |
| 35 CommandUpdater* command_updater) | 39 CommandUpdater* command_updater) |
| 36 : tag_table_(NULL), | 40 : tag_table_(NULL), |
| 37 text_buffer_(NULL), | 41 text_buffer_(NULL), |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 void AutocompleteEditViewGtk::Update(const TabContents* contents) { | 138 void AutocompleteEditViewGtk::Update(const TabContents* contents) { |
| 135 // NOTE: We're getting the URL text here from the ToolbarModel. | 139 // NOTE: We're getting the URL text here from the ToolbarModel. |
| 136 bool visibly_changed_permanent_text = | 140 bool visibly_changed_permanent_text = |
| 137 model_->UpdatePermanentText(toolbar_model_->GetText()); | 141 model_->UpdatePermanentText(toolbar_model_->GetText()); |
| 138 | 142 |
| 139 ToolbarModel::SecurityLevel security_level = | 143 ToolbarModel::SecurityLevel security_level = |
| 140 toolbar_model_->GetSchemeSecurityLevel(); | 144 toolbar_model_->GetSchemeSecurityLevel(); |
| 141 bool changed_security_level = (security_level != scheme_security_level_); | 145 bool changed_security_level = (security_level != scheme_security_level_); |
| 142 scheme_security_level_ = security_level; | 146 scheme_security_level_ = security_level; |
| 143 | 147 |
| 148 // TODO(deanm): This doesn't exactly match Windows. There there is a member |
| 149 // background_color_. I think we can get away with just the level though. |
| 150 if (changed_security_level) { |
| 151 gtk_widget_modify_base(text_view_.get(), |
| 152 GTK_STATE_NORMAL, |
| 153 &kBackgroundColorByLevel[security_level]); |
| 154 } |
| 155 |
| 144 if (contents) { | 156 if (contents) { |
| 145 RevertAll(); | 157 RevertAll(); |
| 146 // TODO(deanm): Tab switching. The Windows code puts some state in a | 158 // TODO(deanm): Tab switching. The Windows code puts some state in a |
| 147 // PropertyBag on the tab contents, and restores state from there. | 159 // PropertyBag on the tab contents, and restores state from there. |
| 148 } else if (visibly_changed_permanent_text) { | 160 } else if (visibly_changed_permanent_text) { |
| 149 RevertAll(); | 161 RevertAll(); |
| 150 // TODO(deanm): There should be code to restore select all here. | 162 // TODO(deanm): There should be code to restore select all here. |
| 151 } else if(changed_security_level) { | 163 } else if (changed_security_level) { |
| 152 EmphasizeURLComponents(); | 164 EmphasizeURLComponents(); |
| 153 } | 165 } |
| 154 } | 166 } |
| 155 | 167 |
| 156 void AutocompleteEditViewGtk::OpenURL(const GURL& url, | 168 void AutocompleteEditViewGtk::OpenURL(const GURL& url, |
| 157 WindowOpenDisposition disposition, | 169 WindowOpenDisposition disposition, |
| 158 PageTransition::Type transition, | 170 PageTransition::Type transition, |
| 159 const GURL& alternate_nav_url, | 171 const GURL& alternate_nav_url, |
| 160 size_t selected_line, | 172 size_t selected_line, |
| 161 const std::wstring& keyword) { | 173 const std::wstring& keyword) { |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 511 gtk_text_buffer_remove_all_tags(text_buffer_, &start, &end); | 523 gtk_text_buffer_remove_all_tags(text_buffer_, &start, &end); |
| 512 } | 524 } |
| 513 | 525 |
| 514 // Emphasize the scheme for security UI display purposes (if necessary). | 526 // Emphasize the scheme for security UI display purposes (if necessary). |
| 515 if (!model_->user_input_in_progress() && parts.scheme.is_nonempty() && | 527 if (!model_->user_input_in_progress() && parts.scheme.is_nonempty() && |
| 516 (scheme_security_level_ != ToolbarModel::NORMAL)) { | 528 (scheme_security_level_ != ToolbarModel::NORMAL)) { |
| 517 gtk_text_buffer_get_iter_at_line_index(text_buffer_, &start, 0, | 529 gtk_text_buffer_get_iter_at_line_index(text_buffer_, &start, 0, |
| 518 parts.scheme.begin); | 530 parts.scheme.begin); |
| 519 gtk_text_buffer_get_iter_at_line_index(text_buffer_, &end, 0, | 531 gtk_text_buffer_get_iter_at_line_index(text_buffer_, &end, 0, |
| 520 parts.scheme.end()); | 532 parts.scheme.end()); |
| 521 const GdkColor* background; | |
| 522 if (scheme_security_level_ == ToolbarModel::SECURE) { | 533 if (scheme_security_level_ == ToolbarModel::SECURE) { |
| 523 background = &kSecureBackgroundColor; | |
| 524 gtk_text_buffer_apply_tag(text_buffer_, secure_scheme_tag_, | 534 gtk_text_buffer_apply_tag(text_buffer_, secure_scheme_tag_, |
| 525 &start, &end); | 535 &start, &end); |
| 526 } else { | 536 } else { |
| 527 background = &kInsecureBackgroundColor; | |
| 528 gtk_text_buffer_apply_tag(text_buffer_, insecure_scheme_tag_, | 537 gtk_text_buffer_apply_tag(text_buffer_, insecure_scheme_tag_, |
| 529 &start, &end); | 538 &start, &end); |
| 530 } | 539 } |
| 531 gtk_widget_modify_base(text_view_.get(), GTK_STATE_NORMAL, background); | |
| 532 } | 540 } |
| 533 } | 541 } |
| 534 | 542 |
| 535 void AutocompleteEditViewGtk::TextChanged() { | 543 void AutocompleteEditViewGtk::TextChanged() { |
| 536 EmphasizeURLComponents(); | 544 EmphasizeURLComponents(); |
| 537 controller_->OnChanged(); | 545 controller_->OnChanged(); |
| 538 } | 546 } |
| OLD | NEW |