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

Side by Side Diff: chrome/browser/views/location_bar_view.h

Issue 1056002: Omnibox M5 work, part 1: Security changes... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 9 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
« no previous file with comments | « chrome/browser/views/app_launcher.cc ('k') | chrome/browser/views/location_bar_view.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 #ifndef CHROME_BROWSER_VIEWS_LOCATION_BAR_VIEW_H_ 5 #ifndef CHROME_BROWSER_VIEWS_LOCATION_BAR_VIEW_H_
6 #define CHROME_BROWSER_VIEWS_LOCATION_BAR_VIEW_H_ 6 #define CHROME_BROWSER_VIEWS_LOCATION_BAR_VIEW_H_
7 7
8 #include <string> 8 #include <string>
9 #include <map> 9 #include <map>
10 #include <vector> 10 #include <vector>
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 // editing. 68 // editing.
69 virtual void OnInputInProgress(bool in_progress) = 0; 69 virtual void OnInputInProgress(bool in_progress) = 0;
70 }; 70 };
71 71
72 enum ColorKind { 72 enum ColorKind {
73 BACKGROUND = 0, 73 BACKGROUND = 0,
74 TEXT, 74 TEXT,
75 SELECTED_TEXT, 75 SELECTED_TEXT,
76 DEEMPHASIZED_TEXT, 76 DEEMPHASIZED_TEXT,
77 SECURITY_TEXT, 77 SECURITY_TEXT,
78 SECURITY_INFO_BUBBLE_TEXT,
79 SCHEME_STRIKEOUT,
80 NUM_KINDS
81 }; 78 };
82 79
83 LocationBarView(Profile* profile, 80 LocationBarView(Profile* profile,
84 CommandUpdater* command_updater, 81 CommandUpdater* command_updater,
85 ToolbarModel* model, 82 ToolbarModel* model,
86 Delegate* delegate, 83 Delegate* delegate,
87 bool popup_window_mode, 84 bool popup_window_mode,
88 const BubblePositioner* bubble_positioner); 85 const BubblePositioner* bubble_positioner);
89 virtual ~LocationBarView(); 86 virtual ~LocationBarView();
90 87
91 void Init(); 88 void Init();
92 89
93 // Returns whether this instance has been initialized by callin Init. Init can 90 // Returns whether this instance has been initialized by callin Init. Init can
94 // only be called when the receiving instance is attached to a view container. 91 // only be called when the receiving instance is attached to a view container.
95 bool IsInitialized() const; 92 bool IsInitialized() const;
96 93
97 // Returns the appropriate color for the desired kind, based on the user's 94 // Returns the appropriate color for the desired kind, based on the user's
98 // system theme. 95 // system theme.
99 static SkColor GetColor(bool is_secure, ColorKind kind); 96 static SkColor GetColor(ToolbarModel::SecurityLevel security_level,
97 ColorKind kind);
100 98
101 // Updates the location bar. We also reset the bar's permanent text and 99 // Updates the location bar. We also reset the bar's permanent text and
102 // security style, and, if |tab_for_state_restoring| is non-NULL, also restore 100 // security style, and, if |tab_for_state_restoring| is non-NULL, also restore
103 // saved state that the tab holds. 101 // saved state that the tab holds.
104 void Update(const TabContents* tab_for_state_restoring); 102 void Update(const TabContents* tab_for_state_restoring);
105 103
106 void SetProfile(Profile* profile); 104 void SetProfile(Profile* profile);
107 Profile* profile() const { return profile_; } 105 Profile* profile() const { return profile_; }
108 106
109 // Returns the current TabContents. 107 // Returns the current TabContents.
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 virtual ExtensionAction* GetPageAction(size_t index); 182 virtual ExtensionAction* GetPageAction(size_t index);
185 virtual ExtensionAction* GetVisiblePageAction(size_t index); 183 virtual ExtensionAction* GetVisiblePageAction(size_t index);
186 virtual void TestPageActionPressed(size_t index); 184 virtual void TestPageActionPressed(size_t index);
187 185
188 static const int kVertMargin; 186 static const int kVertMargin;
189 187
190 protected: 188 protected:
191 void Focus(); 189 void Focus();
192 190
193 private: 191 private:
192 // SecurityImageView is used to display the appropriate status icon when the
193 // current URL's scheme is https.
194 class SecurityImageView : public views::ImageView {
195 public:
196 explicit SecurityImageView(const LocationBarView* parent);
197 virtual ~SecurityImageView();
198
199 // Sets the image that should be displayed.
200 void SetSecurityIcon(int resource_id);
201
202 // Overridden from view.
203 virtual bool OnMousePressed(const views::MouseEvent& event);
204
205 private:
206 // The owning LocationBarView.
207 const LocationBarView* parent_;
208
209 DISALLOW_COPY_AND_ASSIGN(SecurityImageView);
210 };
211
194 // View used when the user has selected a keyword. 212 // View used when the user has selected a keyword.
195 // 213 //
196 // SelectedKeywordView maintains two labels. One label contains the 214 // SelectedKeywordView maintains two labels. One label contains the
197 // complete description of the keyword, the second contains a truncated 215 // complete description of the keyword, the second contains a truncated
198 // version of the description. The second is used if there is not enough room 216 // version of the description. The second is used if there is not enough room
199 // to display the complete description. 217 // to display the complete description.
200 class SelectedKeywordView : public views::View { 218 class SelectedKeywordView : public views::View {
201 public: 219 public:
202 explicit SelectedKeywordView(Profile* profile); 220 explicit SelectedKeywordView(Profile* profile);
203 virtual ~SelectedKeywordView(); 221 virtual ~SelectedKeywordView();
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 views::Label trailing_label_; 290 views::Label trailing_label_;
273 291
274 // The keyword. 292 // The keyword.
275 std::wstring keyword_; 293 std::wstring keyword_;
276 294
277 Profile* profile_; 295 Profile* profile_;
278 296
279 DISALLOW_COPY_AND_ASSIGN(KeywordHintView); 297 DISALLOW_COPY_AND_ASSIGN(KeywordHintView);
280 }; 298 };
281 299
282 class ShowInfoBubbleTask;
283 class ShowFirstRunBubbleTask;
284
285 class LocationBarImageView : public views::ImageView,
286 public InfoBubbleDelegate {
287 public:
288 explicit LocationBarImageView(const BubblePositioner* bubble_positioner);
289 virtual ~LocationBarImageView();
290
291 // Overridden from view for the mouse hovering.
292 virtual void OnMouseMoved(const views::MouseEvent& event);
293 virtual void OnMouseExited(const views::MouseEvent& event);
294 virtual bool OnMousePressed(const views::MouseEvent& event) = 0;
295
296 // InfoBubbleDelegate
297 void InfoBubbleClosing(InfoBubble* info_bubble, bool closed_by_escape);
298 bool CloseOnEscape() { return true; }
299
300 virtual void ShowInfoBubble() = 0;
301
302 protected:
303 void ShowInfoBubbleImpl(const std::wstring& text, SkColor text_color);
304
305 private:
306 friend class ShowInfoBubbleTask;
307
308 // The currently shown info bubble if any.
309 InfoBubble* info_bubble_;
310
311 // A task used to display the info bubble when the mouse hovers on the
312 // image.
313 ShowInfoBubbleTask* show_info_bubble_task_;
314
315 // A positioner used to give the info bubble the correct target bounds. The
316 // caller maintains ownership of this and must ensure it's kept alive.
317 const BubblePositioner* bubble_positioner_;
318
319 DISALLOW_COPY_AND_ASSIGN(LocationBarImageView);
320 };
321
322 // SecurityImageView is used to display the lock or warning icon when the
323 // current URL's scheme is https.
324 //
325 // If a message has been set with SetInfoBubbleText, it displays an info
326 // bubble when the mouse hovers on the image.
327 class SecurityImageView : public LocationBarImageView {
328 public:
329 enum Image {
330 LOCK = 0,
331 WARNING
332 };
333
334 SecurityImageView(const LocationBarView* parent,
335 Profile* profile,
336 ToolbarModel* model_,
337 const BubblePositioner* bubble_positioner);
338 virtual ~SecurityImageView();
339
340 // Sets the image that should be displayed.
341 void SetImageShown(Image image);
342
343 // Overridden from view for the mouse hovering.
344 virtual bool OnMousePressed(const views::MouseEvent& event);
345
346 void set_profile(Profile* profile) { profile_ = profile; }
347
348 virtual void ShowInfoBubble();
349
350 private:
351 // The lock icon shown when using HTTPS.
352 static SkBitmap* lock_icon_;
353
354 // The warning icon shown when HTTPS is broken.
355 static SkBitmap* warning_icon_;
356
357 // A task used to display the info bubble when the mouse hovers on the
358 // image.
359 ShowInfoBubbleTask* show_info_bubble_task_;
360
361 // The owning LocationBarView.
362 const LocationBarView* parent_;
363
364 Profile* profile_;
365
366 ToolbarModel* model_;
367
368 DISALLOW_COPY_AND_ASSIGN(SecurityImageView);
369 };
370
371 class ContentSettingImageView : public views::ImageView, 300 class ContentSettingImageView : public views::ImageView,
372 public InfoBubbleDelegate { 301 public InfoBubbleDelegate {
373 public: 302 public:
374 ContentSettingImageView(ContentSettingsType content_type, 303 ContentSettingImageView(ContentSettingsType content_type,
375 const LocationBarView* parent, 304 const LocationBarView* parent,
376 Profile* profile, 305 Profile* profile,
377 const BubblePositioner* bubble_positioner); 306 const BubblePositioner* bubble_positioner);
378 virtual ~ContentSettingImageView(); 307 virtual ~ContentSettingImageView();
379 308
380 void set_profile(Profile* profile) { profile_ = profile; } 309 void set_profile(Profile* profile) { profile_ = profile; }
(...skipping 23 matching lines...) Expand all
404 // A positioner used to give the info bubble the correct target bounds. The 333 // A positioner used to give the info bubble the correct target bounds. The
405 // caller maintains ownership of this and must ensure it's kept alive. 334 // caller maintains ownership of this and must ensure it's kept alive.
406 const BubblePositioner* bubble_positioner_; 335 const BubblePositioner* bubble_positioner_;
407 336
408 DISALLOW_IMPLICIT_CONSTRUCTORS(ContentSettingImageView); 337 DISALLOW_IMPLICIT_CONSTRUCTORS(ContentSettingImageView);
409 }; 338 };
410 typedef std::vector<ContentSettingImageView*> ContentSettingViews; 339 typedef std::vector<ContentSettingImageView*> ContentSettingViews;
411 340
412 // PageActionImageView is used to display the icon for a given PageAction 341 // PageActionImageView is used to display the icon for a given PageAction
413 // and notify the extension when the icon is clicked. 342 // and notify the extension when the icon is clicked.
414 class PageActionImageView : public LocationBarImageView, 343 class PageActionImageView : public views::ImageView,
415 public ImageLoadingTracker::Observer, 344 public ImageLoadingTracker::Observer,
416 public ExtensionContextMenuModel::PopupDelegate, 345 public ExtensionContextMenuModel::PopupDelegate,
417 public ExtensionPopup::Observer { 346 public ExtensionPopup::Observer {
418 public: 347 public:
419 PageActionImageView(LocationBarView* owner, 348 PageActionImageView(LocationBarView* owner,
420 Profile* profile, 349 Profile* profile,
421 ExtensionAction* page_action, 350 ExtensionAction* page_action);
422 const BubblePositioner* bubble_positioner);
423 virtual ~PageActionImageView(); 351 virtual ~PageActionImageView();
424 352
425 ExtensionAction* page_action() { return page_action_; } 353 ExtensionAction* page_action() { return page_action_; }
426 354
427 int current_tab_id() { return current_tab_id_; } 355 int current_tab_id() { return current_tab_id_; }
428 356
429 void set_preview_enabled(bool preview_enabled) { 357 void set_preview_enabled(bool preview_enabled) {
430 preview_enabled_ = preview_enabled; 358 preview_enabled_ = preview_enabled;
431 } 359 }
432 360
433 // Overridden from view. 361 // Overridden from view.
434 virtual void OnMouseMoved(const views::MouseEvent& event);
435 virtual bool OnMousePressed(const views::MouseEvent& event); 362 virtual bool OnMousePressed(const views::MouseEvent& event);
436 virtual void OnMouseReleased(const views::MouseEvent& event, bool canceled); 363 virtual void OnMouseReleased(const views::MouseEvent& event, bool canceled);
437 364
438 // Overridden from LocationBarImageView.
439 virtual void ShowInfoBubble();
440
441 // Overridden from ImageLoadingTracker. 365 // Overridden from ImageLoadingTracker.
442 virtual void OnImageLoaded( 366 virtual void OnImageLoaded(
443 SkBitmap* image, ExtensionResource resource, int index); 367 SkBitmap* image, ExtensionResource resource, int index);
444 368
445 // Overridden from ExtensionContextMenuModelModel::Delegate 369 // Overridden from ExtensionContextMenuModelModel::Delegate
446 virtual void InspectPopup(ExtensionAction* action); 370 virtual void InspectPopup(ExtensionAction* action);
447 371
448 // Overridden from ExtensionPopup::Observer 372 // Overridden from ExtensionPopup::Observer
449 virtual void ExtensionPopupClosed(ExtensionPopup* popup); 373 virtual void ExtensionPopupClosed(ExtensionPopup* popup);
450 374
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 // with preferred width |pref_width| at its preferred size. If this returns 448 // with preferred width |pref_width| at its preferred size. If this returns
525 // true, the preferred size should be used. If this returns false, the 449 // true, the preferred size should be used. If this returns false, the
526 // minimum size of the view should be used. 450 // minimum size of the view should be used.
527 bool UsePref(int pref_width, int available_width); 451 bool UsePref(int pref_width, int available_width);
528 452
529 // Returns true if the view needs to be resized. This determines whether the 453 // Returns true if the view needs to be resized. This determines whether the
530 // min or pref should be used, and returns true if the view is not at that 454 // min or pref should be used, and returns true if the view is not at that
531 // size. 455 // size.
532 bool NeedsResize(View* view, int available_width); 456 bool NeedsResize(View* view, int available_width);
533 457
534 // Adjusts the keyword hint, selected keyword and type to search views 458 // Adjusts the keyword hint, selected keyword view, type to search label, and
535 // based on the contents of the edit. Returns true if something changed that 459 // security info label based on the contents of the edit. Returns true if
536 // necessitates a layout. 460 // something changed that necessitates a layout.
537 bool AdjustHints(int available_width); 461 bool AdjustAutocollapseViews(int available_width);
538 462
539 // If View fits in the specified region, it is made visible and the 463 // If View fits in the specified region, it is made visible and the
540 // bounds are adjusted appropriately. If the View does not fit, it is 464 // bounds are adjusted appropriately. If the View does not fit, it is
541 // made invisible. 465 // made invisible.
542 void LayoutView(bool leading, views::View* view, int available_width, 466 void LayoutView(bool leading, views::View* view, int available_width,
543 gfx::Rect* bounds); 467 gfx::Rect* bounds);
544 468
545 // Sets the security icon to display. Note that no repaint is done.
546 void SetSecurityIcon(ToolbarModel::Icon icon);
547
548 // Update the visibility state of the Content Blocked icons to reflect what is 469 // Update the visibility state of the Content Blocked icons to reflect what is
549 // actually blocked on the current page. 470 // actually blocked on the current page.
550 void RefreshContentSettingViews(); 471 void RefreshContentSettingViews();
551 472
552 // Delete all page action views that we have created. 473 // Delete all page action views that we have created.
553 void DeletePageActionViews(); 474 void DeletePageActionViews();
554 475
555 // Update the views for the Page Actions, to reflect state changes for 476 // Update the views for the Page Actions, to reflect state changes for
556 // PageActions. 477 // PageActions.
557 void RefreshPageActionViews(); 478 void RefreshPageActionViews();
558 479
559 // Sets the text that should be displayed in the info label and its associated
560 // tooltip text. Call with an empty string if the info label should be
561 // hidden.
562 void SetInfoText(const std::wstring& text,
563 ToolbarModel::InfoTextType text_type,
564 const std::wstring& tooltip_text);
565
566 // Sets the visibility of view to new_vis. Returns whether the visibility 480 // Sets the visibility of view to new_vis. Returns whether the visibility
567 // changed. 481 // changed.
568 bool ToggleVisibility(bool new_vis, views::View* view); 482 bool ToggleVisibility(bool new_vis, views::View* view);
569 483
570 #if defined(OS_WIN) 484 #if defined(OS_WIN)
571 // Helper for the Mouse event handlers that does all the real work. 485 // Helper for the Mouse event handlers that does all the real work.
572 void OnMouseEvent(const views::MouseEvent& event, UINT msg); 486 void OnMouseEvent(const views::MouseEvent& event, UINT msg);
573 #endif 487 #endif
574 488
575 // Helper to show the first run info bubble. 489 // Helper to show the first run info bubble.
(...skipping 27 matching lines...) Expand all
603 517
604 // The user's desired disposition for how their input should be opened 518 // The user's desired disposition for how their input should be opened
605 WindowOpenDisposition disposition_; 519 WindowOpenDisposition disposition_;
606 520
607 // The transition type to use for the navigation 521 // The transition type to use for the navigation
608 PageTransition::Type transition_; 522 PageTransition::Type transition_;
609 523
610 // Font used by edit and some of the hints. 524 // Font used by edit and some of the hints.
611 gfx::Font font_; 525 gfx::Font font_;
612 526
527 // The view that shows the lock/warning when in HTTPS mode.
528 SecurityImageView security_image_view_;
529
613 // Location_entry view wrapper 530 // Location_entry view wrapper
614 views::NativeViewHost* location_entry_view_; 531 views::NativeViewHost* location_entry_view_;
615 532
616 // The following views are used to provide hints and remind the user as to 533 // The following views are used to provide hints and remind the user as to
617 // what is going in the edit. They are all added a children of the 534 // what is going in the edit. They are all added a children of the
618 // LocationBarView. At most one is visible at a time. Preference is 535 // LocationBarView. At most one is visible at a time. Preference is
619 // given to the keyword_view_, then hint_view_, then type_to_search_view_. 536 // given to the keyword_view_, then hint_view_, then type_to_search_view_.
537 // These, as well as |security_info_label_|, autocollapse when the edit needs
538 // the room.
620 539
621 // Shown if the user has selected a keyword. 540 // Shown if the user has selected a keyword.
622 SelectedKeywordView selected_keyword_view_; 541 SelectedKeywordView selected_keyword_view_;
623 542
624 // Shown if the selected url has a corresponding keyword. 543 // Shown if the selected url has a corresponding keyword.
625 KeywordHintView keyword_hint_view_; 544 KeywordHintView keyword_hint_view_;
626 545
627 // Shown if the text is not a keyword or url. 546 // Shown if the text is not a keyword or url.
628 views::Label type_to_search_view_; 547 views::Label type_to_search_view_;
629 548
630 // The view that shows the lock/warning when in HTTPS mode. 549 // A label displayed on the right side of the box to show more information
631 SecurityImageView security_image_view_; 550 // about certain security states.
551 views::Label security_info_label_;
632 552
633 // The content setting views. 553 // The content setting views.
634 ContentSettingViews content_setting_views_; 554 ContentSettingViews content_setting_views_;
635 555
636 // The page action icon views. 556 // The page action icon views.
637 PageActionViews page_action_views_; 557 PageActionViews page_action_views_;
638 558
639 // A label displayed after the lock icon to show some extra information.
640 views::Label info_label_;
641
642 // When true, the location bar view is read only and also is has a slightly 559 // When true, the location bar view is read only and also is has a slightly
643 // different presentation (font size / color). This is used for popups. 560 // different presentation (font size / color). This is used for popups.
644 bool popup_window_mode_; 561 bool popup_window_mode_;
645 562
646 // Used schedule a task for the first run info bubble. 563 // Used schedule a task for the first run info bubble.
647 ScopedRunnableMethodFactory<LocationBarView> first_run_bubble_; 564 ScopedRunnableMethodFactory<LocationBarView> first_run_bubble_;
648 565
649 // The positioner that places the omnibox and info bubbles. 566 // The positioner that places the omnibox and info bubbles.
650 const BubblePositioner* bubble_positioner_; 567 const BubblePositioner* bubble_positioner_;
651 568
652 // Storage of string needed for accessibility. 569 // Storage of string needed for accessibility.
653 std::wstring accessible_name_; 570 std::wstring accessible_name_;
654 571
655 DISALLOW_COPY_AND_ASSIGN(LocationBarView); 572 DISALLOW_COPY_AND_ASSIGN(LocationBarView);
656 }; 573 };
657 574
658 #endif // CHROME_BROWSER_VIEWS_LOCATION_BAR_VIEW_H_ 575 #endif // CHROME_BROWSER_VIEWS_LOCATION_BAR_VIEW_H_
OLDNEW
« no previous file with comments | « chrome/browser/views/app_launcher.cc ('k') | chrome/browser/views/location_bar_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698