OLD | NEW |
---|---|
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 |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
306 1.5 * scale); | 306 1.5 * scale); |
307 path.rLineTo(0, 1); | 307 path.rLineTo(0, 1); |
308 path.close(); | 308 path.close(); |
309 | 309 |
310 if (unscale_at_end && (scale != 1)) | 310 if (unscale_at_end && (scale != 1)) |
311 path.transform(SkMatrix::MakeScale(1.f / scale)); | 311 path.transform(SkMatrix::MakeScale(1.f / scale)); |
312 | 312 |
313 return path; | 313 return path; |
314 } | 314 } |
315 | 315 |
316 // Creates an accessible tab label for screen readers describing the tab status. | |
317 base::string16 GetAccessibleTabLabel(const TabRendererData& data) { | |
318 base::string16 tab_label = data.title; | |
319 | |
320 VLOG(1) << "Tabcontents Error:" << data.network_state << "\n"; | |
321 VLOG(1) << "Tabcontents incognito:" << data.incognito << "\n"; | |
322 | |
323 if (data.network_state == TabRendererData::NETWORK_STATE_ERROR) { | |
324 tab_label.append(l10n_util::GetStringUTF16(IDS_TAB_AX_LABEL_NETWORK_ERROR)); | |
dmazzoni
2016/11/14 21:59:02
Maybe need whitesapce between the existing tab tit
edwardjung
2016/11/24 11:36:43
Switched to hyphen. Also on the advice of lpalmaro
| |
325 } else if (data.incognito) { | |
326 // Incognito tab | |
327 tab_label.append(l10n_util::GetStringUTF16(IDS_TAB_AX_LABEL_INCOGNITO)); | |
328 } else { | |
329 // Alert tab states. | |
330 switch (data.alert_state) { | |
331 case TabAlertState::AUDIO_PLAYING: | |
332 tab_label.append( | |
333 l10n_util::GetStringUTF16(IDS_TAB_AX_LABEL_AUDIO_PLAYING)); | |
334 break; | |
335 case TabAlertState::USB_CONNECTED: | |
336 tab_label.append( | |
337 l10n_util::GetStringUTF16(IDS_TAB_AX_LABEL_USB_CONNECTED)); | |
338 break; | |
339 case TabAlertState::BLUETOOTH_CONNECTED: | |
340 tab_label.append( | |
341 l10n_util::GetStringUTF16(IDS_TAB_AX_LABEL_BLUETOOTH_CONNECTED)); | |
342 break; | |
343 case TabAlertState::MEDIA_RECORDING: | |
344 tab_label.append( | |
345 l10n_util::GetStringUTF16(IDS_TAB_AX_LABEL_MEDIA_RECORDING)); | |
346 break; | |
347 case TabAlertState::AUDIO_MUTING: | |
348 tab_label.append( | |
349 l10n_util::GetStringUTF16(IDS_TAB_AX_LABEL_AUDIO_MUTING)); | |
350 break; | |
351 case TabAlertState::TAB_CAPTURING: | |
352 tab_label.append( | |
353 l10n_util::GetStringUTF16(IDS_TAB_AX_LABEL_TAB_CAPTURING)); | |
354 break; | |
355 default: | |
356 break; | |
357 } | |
358 } | |
359 return tab_label; | |
360 } | |
361 | |
316 } // namespace | 362 } // namespace |
317 | 363 |
318 //////////////////////////////////////////////////////////////////////////////// | 364 //////////////////////////////////////////////////////////////////////////////// |
319 // FaviconCrashAnimation | 365 // FaviconCrashAnimation |
320 // | 366 // |
321 // A custom animation subclass to manage the favicon crash animation. | 367 // A custom animation subclass to manage the favicon crash animation. |
322 class Tab::FaviconCrashAnimation : public gfx::LinearAnimation, | 368 class Tab::FaviconCrashAnimation : public gfx::LinearAnimation, |
323 public gfx::AnimationDelegate { | 369 public gfx::AnimationDelegate { |
324 public: | 370 public: |
325 explicit FaviconCrashAnimation(Tab* target) | 371 explicit FaviconCrashAnimation(Tab* target) |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
487 loading_start_time_ = base::TimeTicks(); | 533 loading_start_time_ = base::TimeTicks(); |
488 waiting_state_ = gfx::ThrobberWaitingState(); | 534 waiting_state_ = gfx::ThrobberWaitingState(); |
489 } | 535 } |
490 | 536 |
491 bool Tab::ThrobberView::CanProcessEventsWithinSubtree() const { | 537 bool Tab::ThrobberView::CanProcessEventsWithinSubtree() const { |
492 return false; | 538 return false; |
493 } | 539 } |
494 | 540 |
495 void Tab::ThrobberView::OnPaint(gfx::Canvas* canvas) { | 541 void Tab::ThrobberView::OnPaint(gfx::Canvas* canvas) { |
496 const TabRendererData::NetworkState state = owner_->data().network_state; | 542 const TabRendererData::NetworkState state = owner_->data().network_state; |
497 if (state == TabRendererData::NETWORK_STATE_NONE) | 543 if (state == TabRendererData::NETWORK_STATE_NONE || |
544 state == TabRendererData::NETWORK_STATE_ERROR) | |
498 return; | 545 return; |
499 | 546 |
500 const ui::ThemeProvider* tp = GetThemeProvider(); | 547 const ui::ThemeProvider* tp = GetThemeProvider(); |
501 const gfx::Rect bounds = GetLocalBounds(); | 548 const gfx::Rect bounds = GetLocalBounds(); |
502 if (state == TabRendererData::NETWORK_STATE_WAITING) { | 549 if (state == TabRendererData::NETWORK_STATE_WAITING) { |
503 if (waiting_start_time_ == base::TimeTicks()) | 550 if (waiting_start_time_ == base::TimeTicks()) |
504 waiting_start_time_ = base::TimeTicks::Now(); | 551 waiting_start_time_ = base::TimeTicks::Now(); |
505 | 552 |
506 waiting_state_.elapsed_time = base::TimeTicks::Now() - waiting_start_time_; | 553 waiting_state_.elapsed_time = base::TimeTicks::Now() - waiting_start_time_; |
507 gfx::PaintThrobberWaiting( | 554 gfx::PaintThrobberWaiting( |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
667 showing_pinned_tab_title_changed_indicator_ = false; | 714 showing_pinned_tab_title_changed_indicator_ = false; |
668 | 715 |
669 DataChanged(old); | 716 DataChanged(old); |
670 | 717 |
671 Layout(); | 718 Layout(); |
672 SchedulePaint(); | 719 SchedulePaint(); |
673 } | 720 } |
674 | 721 |
675 void Tab::UpdateLoadingAnimation(TabRendererData::NetworkState state) { | 722 void Tab::UpdateLoadingAnimation(TabRendererData::NetworkState state) { |
676 if (state == data_.network_state && | 723 if (state == data_.network_state && |
677 state == TabRendererData::NETWORK_STATE_NONE) { | 724 (state == TabRendererData::NETWORK_STATE_NONE || |
678 // If the network state is none and hasn't changed, do nothing. Otherwise we | 725 state == TabRendererData::NETWORK_STATE_ERROR)) { |
679 // need to advance the animation frame. | 726 // If the network state is none or is a network error and hasn't changed, |
727 // do nothing. Otherwise we need to advance the animation frame. | |
680 return; | 728 return; |
681 } | 729 } |
682 | 730 |
683 data_.network_state = state; | 731 data_.network_state = state; |
684 AdvanceLoadingAnimation(); | 732 AdvanceLoadingAnimation(); |
685 } | 733 } |
686 | 734 |
687 void Tab::StartPulse() { | 735 void Tab::StartPulse() { |
688 pulse_animation_->StartThrobbing(std::numeric_limits<int>::max()); | 736 pulse_animation_->StartThrobbing(std::numeric_limits<int>::max()); |
689 } | 737 } |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
944 favicon_ = gfx::ImageSkia(); | 992 favicon_ = gfx::ImageSkia(); |
945 } | 993 } |
946 | 994 |
947 const char* Tab::GetClassName() const { | 995 const char* Tab::GetClassName() const { |
948 return kViewClassName; | 996 return kViewClassName; |
949 } | 997 } |
950 | 998 |
951 bool Tab::GetTooltipText(const gfx::Point& p, base::string16* tooltip) const { | 999 bool Tab::GetTooltipText(const gfx::Point& p, base::string16* tooltip) const { |
952 // Note: Anything that affects the tooltip text should be accounted for when | 1000 // Note: Anything that affects the tooltip text should be accounted for when |
953 // calling TooltipTextChanged() from Tab::DataChanged(). | 1001 // calling TooltipTextChanged() from Tab::DataChanged(). |
954 *tooltip = chrome::AssembleTabTooltipText(data_.title, data_.alert_state); | 1002 *tooltip = chrome::AssembleTabTooltipText(data_.title, data_.alert_state, |
1003 data_.network_state); | |
955 return !tooltip->empty(); | 1004 return !tooltip->empty(); |
956 } | 1005 } |
957 | 1006 |
958 bool Tab::GetTooltipTextOrigin(const gfx::Point& p, gfx::Point* origin) const { | 1007 bool Tab::GetTooltipTextOrigin(const gfx::Point& p, gfx::Point* origin) const { |
959 origin->set_x(title_->x() + 10); | 1008 origin->set_x(title_->x() + 10); |
960 origin->set_y(-4); | 1009 origin->set_y(-4); |
961 return true; | 1010 return true; |
962 } | 1011 } |
963 | 1012 |
964 bool Tab::OnMousePressed(const ui::MouseEvent& event) { | 1013 bool Tab::OnMousePressed(const ui::MouseEvent& event) { |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1093 break; | 1142 break; |
1094 | 1143 |
1095 default: | 1144 default: |
1096 break; | 1145 break; |
1097 } | 1146 } |
1098 event->SetHandled(); | 1147 event->SetHandled(); |
1099 } | 1148 } |
1100 | 1149 |
1101 void Tab::GetAccessibleNodeData(ui::AXNodeData* node_data) { | 1150 void Tab::GetAccessibleNodeData(ui::AXNodeData* node_data) { |
1102 node_data->role = ui::AX_ROLE_TAB; | 1151 node_data->role = ui::AX_ROLE_TAB; |
1103 node_data->SetName(data_.title); | 1152 |
1153 node_data->SetName(GetAccessibleTabLabel(data_)); | |
1104 node_data->AddStateFlag(ui::AX_STATE_MULTISELECTABLE); | 1154 node_data->AddStateFlag(ui::AX_STATE_MULTISELECTABLE); |
1105 node_data->AddStateFlag(ui::AX_STATE_SELECTABLE); | 1155 node_data->AddStateFlag(ui::AX_STATE_SELECTABLE); |
1106 controller_->UpdateTabAccessibilityState(this, node_data); | 1156 controller_->UpdateTabAccessibilityState(this, node_data); |
1107 if (IsSelected()) | 1157 if (IsSelected()) |
1108 node_data->AddStateFlag(ui::AX_STATE_SELECTED); | 1158 node_data->AddStateFlag(ui::AX_STATE_SELECTED); |
1109 } | 1159 } |
1110 | 1160 |
1111 //////////////////////////////////////////////////////////////////////////////// | 1161 //////////////////////////////////////////////////////////////////////////////// |
1112 // Tab, private | 1162 // Tab, private |
1113 | 1163 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1178 // Draw a gray rectangle to represent the tab. This works for pinned tabs as | 1228 // 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. | 1229 // well as regular ones. The active tab has a brigher bar. |
1180 SkColor color = | 1230 SkColor color = |
1181 IsActive() ? kImmersiveActiveTabColor : kImmersiveInactiveTabColor; | 1231 IsActive() ? kImmersiveActiveTabColor : kImmersiveInactiveTabColor; |
1182 gfx::Rect bar_rect = GetImmersiveBarRect(); | 1232 gfx::Rect bar_rect = GetImmersiveBarRect(); |
1183 canvas->FillRect(bar_rect, SkColorSetA(color, alpha)); | 1233 canvas->FillRect(bar_rect, SkColorSetA(color, alpha)); |
1184 | 1234 |
1185 // Paint network activity indicator. | 1235 // Paint network activity indicator. |
1186 // TODO(jamescook): Replace this placeholder animation with a real one. | 1236 // TODO(jamescook): Replace this placeholder animation with a real one. |
1187 // For now, let's go with a Cylon eye effect, but in blue. | 1237 // For now, let's go with a Cylon eye effect, but in blue. |
1188 if (data().network_state != TabRendererData::NETWORK_STATE_NONE) { | 1238 if (data().network_state != TabRendererData::NETWORK_STATE_NONE && |
1239 data().network_state != TabRendererData::NETWORK_STATE_ERROR) { | |
1189 const SkColor kEyeColor = SkColorSetARGB(alpha, 71, 138, 217); | 1240 const SkColor kEyeColor = SkColorSetARGB(alpha, 71, 138, 217); |
1190 int eye_width = bar_rect.width() / 3; | 1241 int eye_width = bar_rect.width() / 3; |
1191 int eye_offset = bar_rect.width() * immersive_loading_step_ / | 1242 int eye_offset = bar_rect.width() * immersive_loading_step_ / |
1192 kImmersiveLoadingStepCount; | 1243 kImmersiveLoadingStepCount; |
1193 if (eye_offset + eye_width < bar_rect.width()) { | 1244 if (eye_offset + eye_width < bar_rect.width()) { |
1194 // Draw a single indicator strip because it fits inside |bar_rect|. | 1245 // Draw a single indicator strip because it fits inside |bar_rect|. |
1195 gfx::Rect eye_rect( | 1246 gfx::Rect eye_rect( |
1196 bar_rect.x() + eye_offset, 0, eye_width, kImmersiveBarHeight); | 1247 bar_rect.x() + eye_offset, 0, eye_width, kImmersiveBarHeight); |
1197 canvas->FillRect(eye_rect, kEyeColor); | 1248 canvas->FillRect(eye_rect, kEyeColor); |
1198 } else { | 1249 } else { |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1383 | 1434 |
1384 void Tab::PaintIcon(gfx::Canvas* canvas) { | 1435 void Tab::PaintIcon(gfx::Canvas* canvas) { |
1385 gfx::Rect bounds = favicon_bounds_; | 1436 gfx::Rect bounds = favicon_bounds_; |
1386 bounds.set_x(GetMirroredXForRect(bounds)); | 1437 bounds.set_x(GetMirroredXForRect(bounds)); |
1387 bounds.Offset(0, favicon_hiding_offset_); | 1438 bounds.Offset(0, favicon_hiding_offset_); |
1388 bounds.Intersect(GetContentsBounds()); | 1439 bounds.Intersect(GetContentsBounds()); |
1389 if (bounds.IsEmpty()) | 1440 if (bounds.IsEmpty()) |
1390 return; | 1441 return; |
1391 | 1442 |
1392 // Throbber will do its own painting. | 1443 // Throbber will do its own painting. |
1393 if (data().network_state != TabRendererData::NETWORK_STATE_NONE) | 1444 if (data().network_state != TabRendererData::NETWORK_STATE_NONE && |
1445 data().network_state != TabRendererData::NETWORK_STATE_ERROR) { | |
1394 return; | 1446 return; |
1395 | 1447 } |
1396 // Ensure that |favicon_| is created. | 1448 // Ensure that |favicon_| is created. |
1397 if (favicon_.isNull()) { | 1449 if (favicon_.isNull()) { |
1398 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); | 1450 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); |
1399 favicon_ = should_display_crashed_favicon_ | 1451 favicon_ = should_display_crashed_favicon_ |
1400 ? *rb->GetImageSkiaNamed(IDR_CRASH_SAD_FAVICON) | 1452 ? *rb->GetImageSkiaNamed(IDR_CRASH_SAD_FAVICON) |
1401 : data().favicon; | 1453 : data().favicon; |
1402 // Themify the icon if it's a chrome:// page or if it's the sadtab favicon. | 1454 // 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 | 1455 // This ensures chrome:// pages are visible over the tab background. This is |
1404 // similar to code in the bookmarks bar. | 1456 // similar to code in the bookmarks bar. |
1405 if (!favicon_.isNull() && | 1457 if (!favicon_.isNull() && |
(...skipping 29 matching lines...) Expand all Loading... | |
1435 immersive_loading_step_ = | 1487 immersive_loading_step_ = |
1436 (immersive_loading_step_ + 1) % kImmersiveLoadingStepCount; | 1488 (immersive_loading_step_ + 1) % kImmersiveLoadingStepCount; |
1437 } else { | 1489 } else { |
1438 immersive_loading_step_ = 0; | 1490 immersive_loading_step_ = 0; |
1439 } | 1491 } |
1440 | 1492 |
1441 SchedulePaintInRect(GetImmersiveBarRect()); | 1493 SchedulePaintInRect(GetImmersiveBarRect()); |
1442 return; | 1494 return; |
1443 } | 1495 } |
1444 | 1496 |
1445 if (state == TabRendererData::NETWORK_STATE_NONE) { | 1497 if (state == TabRendererData::NETWORK_STATE_NONE || |
1498 state == TabRendererData::NETWORK_STATE_ERROR) { | |
1446 throbber_->ResetStartTimes(); | 1499 throbber_->ResetStartTimes(); |
1447 throbber_->SetVisible(false); | 1500 throbber_->SetVisible(false); |
1448 ScheduleIconPaint(); | 1501 ScheduleIconPaint(); |
1449 return; | 1502 return; |
1450 } | 1503 } |
1451 | 1504 |
1452 // Since the throbber can animate for a long time, paint to a separate layer | 1505 // Since the throbber can animate for a long time, paint to a separate layer |
1453 // when possible to reduce repaint overhead. | 1506 // when possible to reduce repaint overhead. |
1454 const bool paint_to_layer = controller_->CanPaintThrobberToLayer(); | 1507 const bool paint_to_layer = controller_->CanPaintThrobberToLayer(); |
1455 if (paint_to_layer != !!throbber_->layer()) { | 1508 if (paint_to_layer != !!throbber_->layer()) { |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1577 SchedulePaintInRect(bounds); | 1630 SchedulePaintInRect(bounds); |
1578 } | 1631 } |
1579 | 1632 |
1580 gfx::Rect Tab::GetImmersiveBarRect() const { | 1633 gfx::Rect Tab::GetImmersiveBarRect() const { |
1581 // The main bar is as wide as the normal tab's horizontal top line. | 1634 // The main bar is as wide as the normal tab's horizontal top line. |
1582 gfx::Rect contents = GetContentsBounds(); | 1635 gfx::Rect contents = GetContentsBounds(); |
1583 contents.set_y(0); | 1636 contents.set_y(0); |
1584 contents.set_height(kImmersiveBarHeight); | 1637 contents.set_height(kImmersiveBarHeight); |
1585 return contents; | 1638 return contents; |
1586 } | 1639 } |
OLD | NEW |