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

Side by Side Diff: chrome/browser/ui/views/tabs/tab.cc

Issue 2581023002: Add tab status to accessibility labels (Closed)
Patch Set: Return early if invalid tab index Created 3 years, 11 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/ui/views/tabs/tab.h" 5 #include "chrome/browser/ui/views/tabs/tab.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <limits> 8 #include <limits>
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/debug/alias.h" 12 #include "base/debug/alias.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "build/build_config.h" 15 #include "build/build_config.h"
16 #include "chrome/browser/themes/theme_properties.h" 16 #include "chrome/browser/themes/theme_properties.h"
17 #include "chrome/browser/ui/browser.h" 17 #include "chrome/browser/ui/browser.h"
18 #include "chrome/browser/ui/layout_constants.h" 18 #include "chrome/browser/ui/layout_constants.h"
19 #include "chrome/browser/ui/tab_contents/core_tab_helper.h" 19 #include "chrome/browser/ui/tab_contents/core_tab_helper.h"
20 #include "chrome/browser/ui/tabs/tab_utils.h" 20 #include "chrome/browser/ui/tabs/tab_utils.h"
21 #include "chrome/browser/ui/view_ids.h" 21 #include "chrome/browser/ui/view_ids.h"
22 #include "chrome/browser/ui/views/frame/browser_view.h"
22 #include "chrome/browser/ui/views/tabs/alert_indicator_button.h" 23 #include "chrome/browser/ui/views/tabs/alert_indicator_button.h"
24 #include "chrome/browser/ui/views/tabs/browser_tab_strip_controller.h"
23 #include "chrome/browser/ui/views/tabs/tab_controller.h" 25 #include "chrome/browser/ui/views/tabs/tab_controller.h"
26 #include "chrome/browser/ui/views/tabs/tab_strip.h"
24 #include "chrome/browser/ui/views/touch_uma/touch_uma.h" 27 #include "chrome/browser/ui/views/touch_uma/touch_uma.h"
25 #include "chrome/common/chrome_switches.h" 28 #include "chrome/common/chrome_switches.h"
26 #include "chrome/common/url_constants.h" 29 #include "chrome/common/url_constants.h"
27 #include "chrome/grit/generated_resources.h" 30 #include "chrome/grit/generated_resources.h"
28 #include "chrome/grit/theme_resources.h" 31 #include "chrome/grit/theme_resources.h"
29 #include "components/grit/components_scaled_resources.h" 32 #include "components/grit/components_scaled_resources.h"
30 #include "components/strings/grit/components_strings.h" 33 #include "components/strings/grit/components_strings.h"
31 #include "content/public/browser/user_metrics.h" 34 #include "content/public/browser/user_metrics.h"
32 #include "content/public/common/url_constants.h" 35 #include "content/public/common/url_constants.h"
33 #include "third_party/skia/include/effects/SkGradientShader.h" 36 #include "third_party/skia/include/effects/SkGradientShader.h"
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after
487 loading_start_time_ = base::TimeTicks(); 490 loading_start_time_ = base::TimeTicks();
488 waiting_state_ = gfx::ThrobberWaitingState(); 491 waiting_state_ = gfx::ThrobberWaitingState();
489 } 492 }
490 493
491 bool Tab::ThrobberView::CanProcessEventsWithinSubtree() const { 494 bool Tab::ThrobberView::CanProcessEventsWithinSubtree() const {
492 return false; 495 return false;
493 } 496 }
494 497
495 void Tab::ThrobberView::OnPaint(gfx::Canvas* canvas) { 498 void Tab::ThrobberView::OnPaint(gfx::Canvas* canvas) {
496 const TabRendererData::NetworkState state = owner_->data().network_state; 499 const TabRendererData::NetworkState state = owner_->data().network_state;
497 if (state == TabRendererData::NETWORK_STATE_NONE) 500 if (state == TabRendererData::NETWORK_STATE_NONE ||
501 state == TabRendererData::NETWORK_STATE_ERROR)
498 return; 502 return;
499 503
500 const ui::ThemeProvider* tp = GetThemeProvider(); 504 const ui::ThemeProvider* tp = GetThemeProvider();
501 const gfx::Rect bounds = GetLocalBounds(); 505 const gfx::Rect bounds = GetLocalBounds();
502 if (state == TabRendererData::NETWORK_STATE_WAITING) { 506 if (state == TabRendererData::NETWORK_STATE_WAITING) {
503 if (waiting_start_time_ == base::TimeTicks()) 507 if (waiting_start_time_ == base::TimeTicks())
504 waiting_start_time_ = base::TimeTicks::Now(); 508 waiting_start_time_ = base::TimeTicks::Now();
505 509
506 waiting_state_.elapsed_time = base::TimeTicks::Now() - waiting_start_time_; 510 waiting_state_.elapsed_time = base::TimeTicks::Now() - waiting_start_time_;
507 gfx::PaintThrobberWaiting( 511 gfx::PaintThrobberWaiting(
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
667 showing_pinned_tab_title_changed_indicator_ = false; 671 showing_pinned_tab_title_changed_indicator_ = false;
668 672
669 DataChanged(old); 673 DataChanged(old);
670 674
671 Layout(); 675 Layout();
672 SchedulePaint(); 676 SchedulePaint();
673 } 677 }
674 678
675 void Tab::UpdateLoadingAnimation(TabRendererData::NetworkState state) { 679 void Tab::UpdateLoadingAnimation(TabRendererData::NetworkState state) {
676 if (state == data_.network_state && 680 if (state == data_.network_state &&
677 state == TabRendererData::NETWORK_STATE_NONE) { 681 (state == TabRendererData::NETWORK_STATE_NONE ||
678 // If the network state is none and hasn't changed, do nothing. Otherwise we 682 state == TabRendererData::NETWORK_STATE_ERROR)) {
679 // need to advance the animation frame. 683 // If the network state is none or is a network error and hasn't changed,
684 // do nothing. Otherwise we need to advance the animation frame.
680 return; 685 return;
681 } 686 }
682 687
683 data_.network_state = state; 688 data_.network_state = state;
684 AdvanceLoadingAnimation(); 689 AdvanceLoadingAnimation();
685 } 690 }
686 691
687 void Tab::StartPulse() { 692 void Tab::StartPulse() {
688 pulse_animation_->StartThrobbing(std::numeric_limits<int>::max()); 693 pulse_animation_->StartThrobbing(std::numeric_limits<int>::max());
689 } 694 }
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
1092 break; 1097 break;
1093 1098
1094 default: 1099 default:
1095 break; 1100 break;
1096 } 1101 }
1097 event->SetHandled(); 1102 event->SetHandled();
1098 } 1103 }
1099 1104
1100 void Tab::GetAccessibleNodeData(ui::AXNodeData* node_data) { 1105 void Tab::GetAccessibleNodeData(ui::AXNodeData* node_data) {
1101 node_data->role = ui::AX_ROLE_TAB; 1106 node_data->role = ui::AX_ROLE_TAB;
1102 node_data->SetName(data_.title); 1107 node_data->SetName(controller_->GetAccessibleTabName(this));
1103 node_data->AddStateFlag(ui::AX_STATE_MULTISELECTABLE); 1108 node_data->AddStateFlag(ui::AX_STATE_MULTISELECTABLE);
1104 node_data->AddStateFlag(ui::AX_STATE_SELECTABLE); 1109 node_data->AddStateFlag(ui::AX_STATE_SELECTABLE);
1105 controller_->UpdateTabAccessibilityState(this, node_data); 1110 controller_->UpdateTabAccessibilityState(this, node_data);
1106 if (IsSelected()) 1111 if (IsSelected())
1107 node_data->AddStateFlag(ui::AX_STATE_SELECTED); 1112 node_data->AddStateFlag(ui::AX_STATE_SELECTED);
1108 } 1113 }
1109 1114
1110 //////////////////////////////////////////////////////////////////////////////// 1115 ////////////////////////////////////////////////////////////////////////////////
1111 // Tab, private 1116 // Tab, private
1112 1117
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1177 // Draw a gray rectangle to represent the tab. This works for pinned tabs as 1182 // Draw a gray rectangle to represent the tab. This works for pinned tabs as
1178 // well as regular ones. The active tab has a brigher bar. 1183 // well as regular ones. The active tab has a brigher bar.
1179 SkColor color = 1184 SkColor color =
1180 IsActive() ? kImmersiveActiveTabColor : kImmersiveInactiveTabColor; 1185 IsActive() ? kImmersiveActiveTabColor : kImmersiveInactiveTabColor;
1181 gfx::Rect bar_rect = GetImmersiveBarRect(); 1186 gfx::Rect bar_rect = GetImmersiveBarRect();
1182 canvas->FillRect(bar_rect, SkColorSetA(color, alpha)); 1187 canvas->FillRect(bar_rect, SkColorSetA(color, alpha));
1183 1188
1184 // Paint network activity indicator. 1189 // Paint network activity indicator.
1185 // TODO(jamescook): Replace this placeholder animation with a real one. 1190 // TODO(jamescook): Replace this placeholder animation with a real one.
1186 // For now, let's go with a Cylon eye effect, but in blue. 1191 // For now, let's go with a Cylon eye effect, but in blue.
1187 if (data().network_state != TabRendererData::NETWORK_STATE_NONE) { 1192 if (data().network_state != TabRendererData::NETWORK_STATE_NONE &&
1193 data().network_state != TabRendererData::NETWORK_STATE_ERROR) {
1188 const SkColor kEyeColor = SkColorSetARGB(alpha, 71, 138, 217); 1194 const SkColor kEyeColor = SkColorSetARGB(alpha, 71, 138, 217);
1189 int eye_width = bar_rect.width() / 3; 1195 int eye_width = bar_rect.width() / 3;
1190 int eye_offset = bar_rect.width() * immersive_loading_step_ / 1196 int eye_offset = bar_rect.width() * immersive_loading_step_ /
1191 kImmersiveLoadingStepCount; 1197 kImmersiveLoadingStepCount;
1192 if (eye_offset + eye_width < bar_rect.width()) { 1198 if (eye_offset + eye_width < bar_rect.width()) {
1193 // Draw a single indicator strip because it fits inside |bar_rect|. 1199 // Draw a single indicator strip because it fits inside |bar_rect|.
1194 gfx::Rect eye_rect( 1200 gfx::Rect eye_rect(
1195 bar_rect.x() + eye_offset, 0, eye_width, kImmersiveBarHeight); 1201 bar_rect.x() + eye_offset, 0, eye_width, kImmersiveBarHeight);
1196 canvas->FillRect(eye_rect, kEyeColor); 1202 canvas->FillRect(eye_rect, kEyeColor);
1197 } else { 1203 } else {
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
1382 1388
1383 void Tab::PaintIcon(gfx::Canvas* canvas) { 1389 void Tab::PaintIcon(gfx::Canvas* canvas) {
1384 gfx::Rect bounds = favicon_bounds_; 1390 gfx::Rect bounds = favicon_bounds_;
1385 bounds.set_x(GetMirroredXForRect(bounds)); 1391 bounds.set_x(GetMirroredXForRect(bounds));
1386 bounds.Offset(0, favicon_hiding_offset_); 1392 bounds.Offset(0, favicon_hiding_offset_);
1387 bounds.Intersect(GetContentsBounds()); 1393 bounds.Intersect(GetContentsBounds());
1388 if (bounds.IsEmpty()) 1394 if (bounds.IsEmpty())
1389 return; 1395 return;
1390 1396
1391 // Throbber will do its own painting. 1397 // Throbber will do its own painting.
1392 if (data().network_state != TabRendererData::NETWORK_STATE_NONE) 1398 if (data().network_state != TabRendererData::NETWORK_STATE_NONE &&
1399 data().network_state != TabRendererData::NETWORK_STATE_ERROR) {
1393 return; 1400 return;
1394 1401 }
1395 // Ensure that |favicon_| is created. 1402 // Ensure that |favicon_| is created.
1396 if (favicon_.isNull()) { 1403 if (favicon_.isNull()) {
1397 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); 1404 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
1398 favicon_ = should_display_crashed_favicon_ 1405 favicon_ = should_display_crashed_favicon_
1399 ? *rb->GetImageSkiaNamed(IDR_CRASH_SAD_FAVICON) 1406 ? *rb->GetImageSkiaNamed(IDR_CRASH_SAD_FAVICON)
1400 : data().favicon; 1407 : data().favicon;
1401 // Themify the icon if it's a chrome:// page or if it's the sadtab favicon. 1408 // Themify the icon if it's a chrome:// page or if it's the sadtab favicon.
1402 // This ensures chrome:// pages are visible over the tab background. This is 1409 // This ensures chrome:// pages are visible over the tab background. This is
1403 // similar to code in the bookmarks bar. 1410 // similar to code in the bookmarks bar.
1404 if (!favicon_.isNull() && 1411 if (!favicon_.isNull() &&
(...skipping 29 matching lines...) Expand all
1434 immersive_loading_step_ = 1441 immersive_loading_step_ =
1435 (immersive_loading_step_ + 1) % kImmersiveLoadingStepCount; 1442 (immersive_loading_step_ + 1) % kImmersiveLoadingStepCount;
1436 } else { 1443 } else {
1437 immersive_loading_step_ = 0; 1444 immersive_loading_step_ = 0;
1438 } 1445 }
1439 1446
1440 SchedulePaintInRect(GetImmersiveBarRect()); 1447 SchedulePaintInRect(GetImmersiveBarRect());
1441 return; 1448 return;
1442 } 1449 }
1443 1450
1444 if (state == TabRendererData::NETWORK_STATE_NONE) { 1451 if (state == TabRendererData::NETWORK_STATE_NONE ||
1452 state == TabRendererData::NETWORK_STATE_ERROR) {
1445 throbber_->ResetStartTimes(); 1453 throbber_->ResetStartTimes();
1446 throbber_->SetVisible(false); 1454 throbber_->SetVisible(false);
1447 ScheduleIconPaint(); 1455 ScheduleIconPaint();
1448 return; 1456 return;
1449 } 1457 }
1450 1458
1451 // Since the throbber can animate for a long time, paint to a separate layer 1459 // Since the throbber can animate for a long time, paint to a separate layer
1452 // when possible to reduce repaint overhead. 1460 // when possible to reduce repaint overhead.
1453 const bool paint_to_layer = controller_->CanPaintThrobberToLayer(); 1461 const bool paint_to_layer = controller_->CanPaintThrobberToLayer();
1454 if (paint_to_layer != !!throbber_->layer()) { 1462 if (paint_to_layer != !!throbber_->layer()) {
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
1576 SchedulePaintInRect(bounds); 1584 SchedulePaintInRect(bounds);
1577 } 1585 }
1578 1586
1579 gfx::Rect Tab::GetImmersiveBarRect() const { 1587 gfx::Rect Tab::GetImmersiveBarRect() const {
1580 // The main bar is as wide as the normal tab's horizontal top line. 1588 // The main bar is as wide as the normal tab's horizontal top line.
1581 gfx::Rect contents = GetContentsBounds(); 1589 gfx::Rect contents = GetContentsBounds();
1582 contents.set_y(0); 1590 contents.set_y(0);
1583 contents.set_height(kImmersiveBarHeight); 1591 contents.set_height(kImmersiveBarHeight);
1584 return contents; 1592 return contents;
1585 } 1593 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/tabs/fake_base_tab_strip_controller.cc ('k') | chrome/browser/ui/views/tabs/tab_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698