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

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

Issue 2497373003: Add tab status to accessibility labels (Closed)
Patch Set: Fix unit tests Created 4 years 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 403 matching lines...) Expand 10 before | Expand all | Expand 10 after
1093 break; 1098 break;
1094 1099
1095 default: 1100 default:
1096 break; 1101 break;
1097 } 1102 }
1098 event->SetHandled(); 1103 event->SetHandled();
1099 } 1104 }
1100 1105
1101 void Tab::GetAccessibleNodeData(ui::AXNodeData* node_data) { 1106 void Tab::GetAccessibleNodeData(ui::AXNodeData* node_data) {
1102 node_data->role = ui::AX_ROLE_TAB; 1107 node_data->role = ui::AX_ROLE_TAB;
1103 node_data->SetName(data_.title); 1108 node_data->SetName(controller_->GetAccessibleTabName());
1104 node_data->AddStateFlag(ui::AX_STATE_MULTISELECTABLE); 1109 node_data->AddStateFlag(ui::AX_STATE_MULTISELECTABLE);
1105 node_data->AddStateFlag(ui::AX_STATE_SELECTABLE); 1110 node_data->AddStateFlag(ui::AX_STATE_SELECTABLE);
1106 controller_->UpdateTabAccessibilityState(this, node_data); 1111 controller_->UpdateTabAccessibilityState(this, node_data);
1107 if (IsSelected()) 1112 if (IsSelected())
1108 node_data->AddStateFlag(ui::AX_STATE_SELECTED); 1113 node_data->AddStateFlag(ui::AX_STATE_SELECTED);
1109 } 1114 }
1110 1115
1111 //////////////////////////////////////////////////////////////////////////////// 1116 ////////////////////////////////////////////////////////////////////////////////
1112 // Tab, private 1117 // Tab, private
1113 1118
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1178 // Draw a gray rectangle to represent the tab. This works for pinned tabs as 1183 // Draw a gray rectangle to represent the tab. This works for pinned tabs as
1179 // well as regular ones. The active tab has a brigher bar. 1184 // well as regular ones. The active tab has a brigher bar.
1180 SkColor color = 1185 SkColor color =
1181 IsActive() ? kImmersiveActiveTabColor : kImmersiveInactiveTabColor; 1186 IsActive() ? kImmersiveActiveTabColor : kImmersiveInactiveTabColor;
1182 gfx::Rect bar_rect = GetImmersiveBarRect(); 1187 gfx::Rect bar_rect = GetImmersiveBarRect();
1183 canvas->FillRect(bar_rect, SkColorSetA(color, alpha)); 1188 canvas->FillRect(bar_rect, SkColorSetA(color, alpha));
1184 1189
1185 // Paint network activity indicator. 1190 // Paint network activity indicator.
1186 // TODO(jamescook): Replace this placeholder animation with a real one. 1191 // TODO(jamescook): Replace this placeholder animation with a real one.
1187 // For now, let's go with a Cylon eye effect, but in blue. 1192 // For now, let's go with a Cylon eye effect, but in blue.
1188 if (data().network_state != TabRendererData::NETWORK_STATE_NONE) { 1193 if (data().network_state != TabRendererData::NETWORK_STATE_NONE &&
1194 data().network_state != TabRendererData::NETWORK_STATE_ERROR) {
1189 const SkColor kEyeColor = SkColorSetARGB(alpha, 71, 138, 217); 1195 const SkColor kEyeColor = SkColorSetARGB(alpha, 71, 138, 217);
1190 int eye_width = bar_rect.width() / 3; 1196 int eye_width = bar_rect.width() / 3;
1191 int eye_offset = bar_rect.width() * immersive_loading_step_ / 1197 int eye_offset = bar_rect.width() * immersive_loading_step_ /
1192 kImmersiveLoadingStepCount; 1198 kImmersiveLoadingStepCount;
1193 if (eye_offset + eye_width < bar_rect.width()) { 1199 if (eye_offset + eye_width < bar_rect.width()) {
1194 // Draw a single indicator strip because it fits inside |bar_rect|. 1200 // Draw a single indicator strip because it fits inside |bar_rect|.
1195 gfx::Rect eye_rect( 1201 gfx::Rect eye_rect(
1196 bar_rect.x() + eye_offset, 0, eye_width, kImmersiveBarHeight); 1202 bar_rect.x() + eye_offset, 0, eye_width, kImmersiveBarHeight);
1197 canvas->FillRect(eye_rect, kEyeColor); 1203 canvas->FillRect(eye_rect, kEyeColor);
1198 } else { 1204 } else {
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
1383 1389
1384 void Tab::PaintIcon(gfx::Canvas* canvas) { 1390 void Tab::PaintIcon(gfx::Canvas* canvas) {
1385 gfx::Rect bounds = favicon_bounds_; 1391 gfx::Rect bounds = favicon_bounds_;
1386 bounds.set_x(GetMirroredXForRect(bounds)); 1392 bounds.set_x(GetMirroredXForRect(bounds));
1387 bounds.Offset(0, favicon_hiding_offset_); 1393 bounds.Offset(0, favicon_hiding_offset_);
1388 bounds.Intersect(GetContentsBounds()); 1394 bounds.Intersect(GetContentsBounds());
1389 if (bounds.IsEmpty()) 1395 if (bounds.IsEmpty())
1390 return; 1396 return;
1391 1397
1392 // Throbber will do its own painting. 1398 // Throbber will do its own painting.
1393 if (data().network_state != TabRendererData::NETWORK_STATE_NONE) 1399 if (data().network_state != TabRendererData::NETWORK_STATE_NONE &&
1400 data().network_state != TabRendererData::NETWORK_STATE_ERROR) {
1394 return; 1401 return;
1395 1402 }
1396 // Ensure that |favicon_| is created. 1403 // Ensure that |favicon_| is created.
1397 if (favicon_.isNull()) { 1404 if (favicon_.isNull()) {
1398 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); 1405 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
1399 favicon_ = should_display_crashed_favicon_ 1406 favicon_ = should_display_crashed_favicon_
1400 ? *rb->GetImageSkiaNamed(IDR_CRASH_SAD_FAVICON) 1407 ? *rb->GetImageSkiaNamed(IDR_CRASH_SAD_FAVICON)
1401 : data().favicon; 1408 : data().favicon;
1402 // Themify the icon if it's a chrome:// page or if it's the sadtab favicon. 1409 // Themify the icon if it's a chrome:// page or if it's the sadtab favicon.
1403 // This ensures chrome:// pages are visible over the tab background. This is 1410 // This ensures chrome:// pages are visible over the tab background. This is
1404 // similar to code in the bookmarks bar. 1411 // similar to code in the bookmarks bar.
1405 if (!favicon_.isNull() && 1412 if (!favicon_.isNull() &&
(...skipping 29 matching lines...) Expand all
1435 immersive_loading_step_ = 1442 immersive_loading_step_ =
1436 (immersive_loading_step_ + 1) % kImmersiveLoadingStepCount; 1443 (immersive_loading_step_ + 1) % kImmersiveLoadingStepCount;
1437 } else { 1444 } else {
1438 immersive_loading_step_ = 0; 1445 immersive_loading_step_ = 0;
1439 } 1446 }
1440 1447
1441 SchedulePaintInRect(GetImmersiveBarRect()); 1448 SchedulePaintInRect(GetImmersiveBarRect());
1442 return; 1449 return;
1443 } 1450 }
1444 1451
1445 if (state == TabRendererData::NETWORK_STATE_NONE) { 1452 if (state == TabRendererData::NETWORK_STATE_NONE ||
1453 state == TabRendererData::NETWORK_STATE_ERROR) {
1446 throbber_->ResetStartTimes(); 1454 throbber_->ResetStartTimes();
1447 throbber_->SetVisible(false); 1455 throbber_->SetVisible(false);
1448 ScheduleIconPaint(); 1456 ScheduleIconPaint();
1449 return; 1457 return;
1450 } 1458 }
1451 1459
1452 // Since the throbber can animate for a long time, paint to a separate layer 1460 // Since the throbber can animate for a long time, paint to a separate layer
1453 // when possible to reduce repaint overhead. 1461 // when possible to reduce repaint overhead.
1454 const bool paint_to_layer = controller_->CanPaintThrobberToLayer(); 1462 const bool paint_to_layer = controller_->CanPaintThrobberToLayer();
1455 if (paint_to_layer != !!throbber_->layer()) { 1463 if (paint_to_layer != !!throbber_->layer()) {
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
1577 SchedulePaintInRect(bounds); 1585 SchedulePaintInRect(bounds);
1578 } 1586 }
1579 1587
1580 gfx::Rect Tab::GetImmersiveBarRect() const { 1588 gfx::Rect Tab::GetImmersiveBarRect() const {
1581 // The main bar is as wide as the normal tab's horizontal top line. 1589 // The main bar is as wide as the normal tab's horizontal top line.
1582 gfx::Rect contents = GetContentsBounds(); 1590 gfx::Rect contents = GetContentsBounds();
1583 contents.set_y(0); 1591 contents.set_y(0);
1584 contents.set_height(kImmersiveBarHeight); 1592 contents.set_height(kImmersiveBarHeight);
1585 return contents; 1593 return contents;
1586 } 1594 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698